How to pass custom parameters to sendy via node js api? - javascript

I am trying to pass custom data in sendy via api of sendy. Sendy has custom field attributes in which we can pass data. I am using a sendy node js package whose link is provided on sendy website. the issue is that i am not able to pass custom field data to sendy api. Here is my code
var params = {
email: email2,
custom: {
'assignmentDetail':assignmentLink,
'submissionDetail':submissionDetail,
'FormLink':reviewerFormLink,
},
list_id: ListID,
api_key: 'vQzxtX76pNFekG4w5BzC'
};
sendy.subscribe(params, function (err, result) { if (err){
console.log(err.toString());
}else{
UpdateData(recordID, email2, ListID);
console.log('Subscribed succesfully');}
});
the custom field data is not being passed in the sendy. Please help

I have found the solution to my problem. It is very simple. You need to make your custom fields in enclosed in quotes and you are done. Just like this
var params = {
email: email2,
//make sure custom field names are same otherwise sendy would igore the fields
'assignmentDetail':assignmentLink,
'submissionDetail':submissionDetail,
'FormLink':reviewerFormLink,
list_id: ListID,
api_key: 'vQzxtX76pNFekG4w5BzC'
};
sendy.subscribe(params, function (err, result) { if (err){
console.log(err.toString());
}else{
UpdateData(recordID, email2, ListID);
console.log('Subscribed succesfully');}
});

Related

Failed to append data in .json file using node

I want to append my data which is array of object format to the existing .json file so I have written code for it, but on stackoverflow I noticed so many developers suggesting before appending to existing json file first read file and then push new data to existing json file. So I followed this and made changes according to this but getting error :
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined
Code written in node
newdata=[
{
UserId: '11',
UserName: 'harry',
},
{
UserId: 12,
UserName: 'David',
}
];
fs.readFile('results.json', function (err, data) {
if(data === '') {
json = JSON.parse(newdata);
json.push(newdata);
}
fs.writeFile("results.json", JSON.stringify(json));
})
This error is because you are using the .writeFile in a wrong way.
Try something like this:
fs.writeFile('results.json', JSON.stringify(newData), function(err) {
if (err) throw err;
});
A short explanation:
The ERR_INVALID_CALLBACK in the error message is the missing of the function informed in the last parameter in the example above.
fs.writeFile(<file>, <content>, <callback>)

How to properly create a custom field in salesforce using jsforce?

I am trying to create a customfield in jsforce and am having a heck of a time doing it. I can create a custom object fine, but when trying to make a field so the clients users to sort their leads by it is giving me a heckof a time. This is what I did to create a object
var jsforce = require('jsforce');
var conn = new jsforce.Connection();
conn.login('myemail', 'my password and token', function(err, res) {
if (err) { return console.error(err); }
var metadata = [{
fullName: 'TestObject1__c',
label: 'Test Object 1',
pluralLabel: 'Test Object 1',
nameField: {
type: 'Text',
label: 'Test Object Name'
},
deploymentStatus: 'Deployed',
sharingModel: 'ReadWrite'
}];
conn.metadata.create('CustomObject', metadata, function(err, results) {
if (err) { console.err(err); }
for (var i=0; i < results.length; i++) {
var result = results[i];
console.log('success ? : ' + result.success);
console.log('fullName : ' + result.fullName);
}
});
{
if (err) { return console.error(err); }
console.log(res);
}
})
That works fine but it is not what I need. Any help would be greatly appreciated as the client wants this out. It is part of a larger project that we have already completed but now the fields have to be dynamically created so the end users don't have to make the fields themselves in order for us to push the data to their account. We are currently pushing stuff but its under another field whose name doesn't make sense
I have been able to accomplish this by making a package in the salesforce website. All my clients users have to do is to click a simple link click install and it makes a list view and creates the fields i need.

.save() not working inside callback function

I'm currently using the "request" module to get data from an external page:
if i use the following code, it doesn't work:
request(SITE_URL, function (error, response, body) {
var user = new gasStation({ id: 12345, name: 'Gustavo' });
user.save();
});
But if i make the call outside the request function it works as expected:
var user = new gasStation({ id: 12345, name: 'Gustavo' });
user.save();
request(SITE_URL, function (error, response, body) {
// some stuff
});
Why is this happening?
First never ignore your error handler's. Check if error is true. Also your URL might be malformed check that. Lastly make sure the mongoose model for user is initialized. I only saw initialization outside the request.

Sequelize get request data in hooks?

I'm trying to store some log data for my models on create, update, delete calls. I want to store some data from the request along with some user data also in the request (using express.js).
In the hooks I have some modules for logging.
hooks: {
afterCreate: function (order, options, done) {
// How to get user data stored in express request.
return app.log.set('event', [{message: 'created', data: order, userId: 1}, done]);
}
}
...
The module just makes a record in a table. However it's the userId part I'm having trouble with. I'm using the passport module and it's stored in the request, so how can I get a user object (or any external object for that matter) into the model hooks?
I would like to avoid doing it in a controller or anywhere else as there could be some scripts or other commands that may also enter data.
I also encountered similar problems, which I myself resolved as follows:
First: I declared a Global (universal) hook:
module.exports = sequelize.addHook('beforeCreate',
function(model, options, done) {//hook 2
//handle what you want
//return app.log.set('event', [{message: 'created', data: order, userId: 1}, done]);
});
Then, Before calling model, use call hooks (beforeCreate, beforeBulkUpdate,...) and assigned param request
module.exports = {
CreateUser: function(req, res) {
User.beforeCreate(function(model, options, done) {//hook1
model.request = req;
});
User.create({
id: 1,
username: 'thanh9999',
password: '31231233123'
//ex.....
})
.then(function(success) {
//response success
}, function(err) {
//response error
});
}
};
order hooks called: hook declaration in model → hook 1 → hook 2`.
In addition, you also have to declare hooks for each model.
See more information here.

Sending hidden form field to server on a Wordpress site

I am new to working with Wordpress and I'm using a JQuery plugin called textcomplete with Algolia search to allow users to # mention other users in the comment section of my site as shown in the code below.
$input.textcomplete([
{
match: /\B#(\w*)$/,
search: function(term, callback) {
lastQuery = term;
myIndex.search(term, { hitsPerPage: 5 }, function(err, content) {
if (err) {
throw err;
}
if (content.query === lastQuery) {
callback(content.hits);
}
});
},
template: function (hit) {
console.log(hit);
return hit._highlightResult.display_name.value;
},
replace: function (hit) {
return ' #' + hit.display_name + ' ';
},
index: 1
}
]);
I want to send my hit.display_name variable to the server to use as part of a MySQL query. Normally I would do this by making it a hidden form field and posting it to the php file where it is required (in this case wp-comments-post.php) but with the way comment forms are handled with Wordpress (using a comment_form function and passing it an associative array of objects) I am not sure how to do this...
So my question is how do I access this hit.display_name variable in my wp-comments-post.php file?

Categories

Resources