NodeJS - Integration Tasks
Integration tasks in NodeJS are a set of functions that allow a user to perform some of the most basic tasks such as creating a record, updating a record, etc,.
These integration tasks in Node JS use v2 APIs and you can use them as-is in your code.
Using Node JS Integration Tasks you can,
Points to Remember
You must use only field API names in the input.
The data for your function is the "data" JSON object.
Create a record
Set up functions in a way that records are automatically created based on certain actions. For example, you can trigger the function to create a record in tasks upon changing the status of a lead. Use the CRM.V2.createRecord() task to create records.
The below code shows the Node JS function to create a record in the Leads module using v2 integration task.
CRM = require('zc_service_sdk').integration.CRM
module.exports = function(context, basicIOObj) {
data = {
"data": [{
"Company": "Zylker",
"Last_Name": "Daly",
"First_Name": "Paul",
"Email": "p.daly@zylker.com",
"State": "Texas"
},
{
"Company": "Villa Margarita",
"Last_Name": "Dolan",
"First_Name": "Brian",
"Email": "brian@villa.com",
"State": "Texas"
}
],
"trigger": [
"approval",
"workflow",
"blueprint"
]
};
CRM.V2.createRecord('Leads', data, function(err, response, body) {
if (err) {
console.log('error ' + err);
return;
}
basicIOObj.write(JSON.stringify(body));
context.close();
});
}
Update a Specific Record
Use this task to fetch a specific variable created for your organization.
module.exports = function(context, basicIOObj) {
crm = context.getIntegrationTask().getService("CRM");
data = {
"data": [{
"Last_Name": "daily update here"
}],
"trigger": [
"approval",
"workflow",
"blueprint"
]
};
crm.V2.updateRecord('Leads', "655231000000781018", data, function(err, response, body) {
if (err) {
console.log('error ' + err);
return;
}
basicIOObj.write(JSON.stringify(body));
context.close();
});
}
Get Records
You can use the CRM.V2.getRecords() task to fetch the information of a the records in a module.
The below code shows the Node JS function to fetch the records from the Leads module using v2 integration task.
You must use only field API names in the input.
CRM = require('zc_service_sdk').integration.CRM
module.exports = function(context, basicIOObj) {
CRM.V2.getRecords('Leads', function(err, response, body) {
if (err) {
console.log('error ' + err);
return;
}
basicIOObj.write(JSON.stringify(body));
context.close();
});
}
Get Related Records
Use this task to fetch records from a submodule(related list) related to a record in a parent module in Zoho CRM. For instance, you can fetch the Products related to a particular using the ID of the parent module record.
module.exports = function (context, basicIOObj) {
crm = context.getIntegrationTask().getService("CRM");
//param1 - relationName
//param2 - parentModuleName
//param3 - recordId
crm.V2.getRelatedRecords("Products", "Leads", "655231000000746010", function (err, body) {
if (err) {
console.log('error ' + err);
return;
}
basicIOObj.write(JSON.stringify(body));
context.close();
});
}
Get Org Variables
Use this task to fetch all variables created for your organization.
module.exports = function(context, basicIOObj) {
crm = context.getIntegrationTask().getService("CRM");
crm.V2.getOrgVariables(function(err, body) {
if (err) {
console.log('error ' + err);
return;
}
basicIOObj.write(JSON.stringify(body));
context.close();
});
}
Get a Specific Variable
Use this task to fetch a specific variable created for your organization.
module.exports = function(context, basicIOObj) {
crm = context.getIntegrationTask().getService("CRM");
//param1 - variable Id
//param2 - group Id
crm.V2.getOrgVariableById("655231000000749046", "655231000000749044", function(err, body) {
if (err) {
console.log('error ' + err);
return;
}
basicIOObj.write(JSON.stringify(body));
context.close();
});
}