2020-02-12 07:04:43 -08:00
|
|
|
import {
|
|
|
|
IExecuteFunctions,
|
|
|
|
} from 'n8n-core';
|
|
|
|
|
|
|
|
import {
|
|
|
|
IDataObject,
|
2020-03-31 09:54:44 -07:00
|
|
|
INodeExecutionData,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
2020-02-12 07:04:43 -08:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
import {
|
2021-04-29 02:56:19 -07:00
|
|
|
adjustAccountFields,
|
|
|
|
adjustContactFields,
|
|
|
|
adjustInvoiceFields,
|
|
|
|
adjustLeadFields,
|
|
|
|
adjustPurchaseOrderFields,
|
|
|
|
adjustQuoteFields,
|
|
|
|
adjustSalesOrderFields,
|
|
|
|
handleListing,
|
2020-02-12 07:04:43 -08:00
|
|
|
zohoApiRequest,
|
|
|
|
} from './GenericFunctions';
|
|
|
|
|
|
|
|
import {
|
2021-04-29 02:56:19 -07:00
|
|
|
accountFields,
|
|
|
|
accountOperations,
|
|
|
|
contactFields,
|
|
|
|
contactOperations,
|
|
|
|
dealFields,
|
|
|
|
dealOperations,
|
|
|
|
invoiceFields,
|
|
|
|
invoiceOperations,
|
2020-02-12 07:04:43 -08:00
|
|
|
leadFields,
|
2020-03-31 09:54:44 -07:00
|
|
|
leadOperations,
|
2021-04-29 02:56:19 -07:00
|
|
|
purchaseOrderFields,
|
|
|
|
purchaseOrderOperations,
|
|
|
|
quoteFields,
|
|
|
|
quoteOperations,
|
|
|
|
salesOrderFields,
|
|
|
|
salesOrderOperations,
|
|
|
|
} from './descriptions';
|
2020-02-15 16:23:22 -08:00
|
|
|
|
2020-02-12 07:04:43 -08:00
|
|
|
export class ZohoCrm implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
2021-04-29 02:56:19 -07:00
|
|
|
displayName: 'Zoho',
|
|
|
|
name: 'zoho',
|
|
|
|
icon: 'file:zoho.svg',
|
|
|
|
group: ['transform'],
|
2020-02-12 07:04:43 -08:00
|
|
|
version: 1,
|
2021-04-29 02:56:19 -07:00
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
|
|
description: 'Consume the Zoho API',
|
2020-02-12 07:04:43 -08:00
|
|
|
defaults: {
|
2021-04-29 02:56:19 -07:00
|
|
|
name: 'Zoho',
|
|
|
|
color: '\#CE2232',
|
2020-02-12 07:04:43 -08:00
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'zohoOAuth2Api',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
2021-04-29 02:56:19 -07:00
|
|
|
{
|
|
|
|
name: 'Account',
|
|
|
|
value: 'account',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Contact',
|
|
|
|
value: 'contact',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Deal',
|
|
|
|
value: 'deal',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Invoice',
|
|
|
|
value: 'invoice',
|
|
|
|
},
|
2020-02-12 07:04:43 -08:00
|
|
|
{
|
|
|
|
name: 'Lead',
|
|
|
|
value: 'lead',
|
|
|
|
},
|
2021-04-29 02:56:19 -07:00
|
|
|
{
|
|
|
|
name: 'Purchase Order',
|
|
|
|
value: 'purchaseOrder',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Quote',
|
|
|
|
value: 'quote',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Sales Order',
|
|
|
|
value: 'salesOrder',
|
|
|
|
},
|
2020-02-12 07:04:43 -08:00
|
|
|
],
|
2021-04-29 02:56:19 -07:00
|
|
|
default: 'account',
|
|
|
|
description: 'Resource to consume',
|
2020-02-12 07:04:43 -08:00
|
|
|
},
|
2021-04-29 02:56:19 -07:00
|
|
|
...accountOperations,
|
|
|
|
...accountFields,
|
|
|
|
...contactOperations,
|
|
|
|
...contactFields,
|
|
|
|
...dealOperations,
|
|
|
|
...dealFields,
|
|
|
|
...invoiceOperations,
|
|
|
|
...invoiceFields,
|
2020-02-12 07:04:43 -08:00
|
|
|
...leadOperations,
|
|
|
|
...leadFields,
|
2021-04-29 02:56:19 -07:00
|
|
|
...purchaseOrderOperations,
|
|
|
|
...purchaseOrderFields,
|
|
|
|
...quoteOperations,
|
|
|
|
...quoteFields,
|
|
|
|
...salesOrderOperations,
|
|
|
|
...salesOrderFields,
|
2020-02-12 07:04:43 -08:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
|
|
|
const returnData: IDataObject[] = [];
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
const resource = this.getNodeParameter('resource', 0) as string;
|
|
|
|
const operation = this.getNodeParameter('operation', 0) as string;
|
|
|
|
|
2020-02-12 07:04:43 -08:00
|
|
|
let responseData;
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
|
|
|
|
// https://www.zoho.com/crm/developer/docs/api/insert-records.html
|
|
|
|
// https://www.zoho.com/crm/developer/docs/api/get-records.html
|
|
|
|
// https://www.zoho.com/crm/developer/docs/api/update-specific-record.html
|
|
|
|
// https://www.zoho.com/crm/developer/docs/api/delete-specific-record.html
|
|
|
|
|
|
|
|
if (resource === 'account') {
|
|
|
|
|
|
|
|
// **********************************************************************
|
|
|
|
// account
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
// https://www.zoho.com/crm/developer/docs/api/v2/accounts-response.html
|
|
|
|
|
2020-02-12 07:04:43 -08:00
|
|
|
if (operation === 'create') {
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// account: create
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {
|
|
|
|
Account_Name: this.getNodeParameter('accountName', i),
|
2020-02-12 07:04:43 -08:00
|
|
|
};
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
|
|
|
|
|
|
if (Object.keys(additionalFields).length) {
|
|
|
|
Object.assign(body, adjustAccountFields(additionalFields));
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
responseData = await zohoApiRequest.call(this, 'POST', '/accounts', body);
|
|
|
|
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// account: delete
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const accountId = this.getNodeParameter('accountId', i);
|
|
|
|
|
|
|
|
const endpoint = `/accounts/${accountId}`;
|
|
|
|
responseData = await zohoApiRequest.call(this, 'DELETE', endpoint);
|
|
|
|
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// account: get
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const accountId = this.getNodeParameter('accountId', i);
|
|
|
|
|
|
|
|
const endpoint = `/accounts/${accountId}`;
|
|
|
|
responseData = await zohoApiRequest.call(this, 'GET', endpoint);
|
|
|
|
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// account: getAll
|
|
|
|
// ----------------------------------------
|
|
|
|
|
2021-05-07 01:18:10 -07:00
|
|
|
responseData = await handleListing.call(this, 'GET', '/accounts');
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// account: update
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {};
|
|
|
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
|
|
|
|
|
|
if (Object.keys(updateFields).length) {
|
|
|
|
Object.assign(body, adjustAccountFields(updateFields));
|
2020-03-31 09:54:44 -07:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
const accountId = this.getNodeParameter('accountId', i);
|
|
|
|
|
|
|
|
const endpoint = `/accounts/${accountId}`;
|
|
|
|
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
|
|
|
|
|
2020-02-12 07:04:43 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
} else if (resource === 'contact') {
|
|
|
|
|
|
|
|
// **********************************************************************
|
|
|
|
// contact
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
// https://www.zoho.com/crm/developer/docs/api/v2/contacts-response.html
|
|
|
|
|
|
|
|
if (operation === 'create') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// contact: create
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {
|
2021-05-07 01:58:40 -07:00
|
|
|
Last_Name: this.getNodeParameter('lastName', i),
|
2021-04-29 02:56:19 -07:00
|
|
|
};
|
|
|
|
|
2020-02-15 16:23:22 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
if (Object.keys(additionalFields).length) {
|
|
|
|
Object.assign(body, adjustContactFields(additionalFields));
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
responseData = await zohoApiRequest.call(this, 'POST', '/contacts', body);
|
|
|
|
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// contact: delete
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const contactId = this.getNodeParameter('contactId', i);
|
|
|
|
|
|
|
|
const endpoint = `/contacts/${contactId}`;
|
|
|
|
responseData = await zohoApiRequest.call(this, 'DELETE', endpoint);
|
|
|
|
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// contact: get
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const contactId = this.getNodeParameter('contactId', i);
|
|
|
|
|
|
|
|
const endpoint = `/contacts/${contactId}`;
|
|
|
|
responseData = await zohoApiRequest.call(this, 'GET', endpoint);
|
|
|
|
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// contact: getAll
|
|
|
|
// ----------------------------------------
|
|
|
|
|
2021-05-07 01:18:10 -07:00
|
|
|
responseData = await handleListing.call(this, 'GET', '/contacts');
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// contact: update
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {};
|
|
|
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
|
|
|
|
|
|
if (Object.keys(updateFields).length) {
|
|
|
|
Object.assign(body, adjustContactFields(updateFields));
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
const contactId = this.getNodeParameter('contactId', i);
|
|
|
|
|
|
|
|
const endpoint = `/contacts/${contactId}`;
|
|
|
|
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (resource === 'deal') {
|
|
|
|
|
|
|
|
// **********************************************************************
|
|
|
|
// deal
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
// https://www.zoho.com/crm/developer/docs/api/v2/deals-response.html
|
|
|
|
|
|
|
|
if (operation === 'create') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// deal: create
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {
|
|
|
|
Deal_Name: this.getNodeParameter('Deal_Name', i),
|
|
|
|
Stage: this.getNodeParameter('Stage', i),
|
|
|
|
};
|
|
|
|
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
|
|
|
|
|
|
if (Object.keys(additionalFields).length) {
|
|
|
|
Object.assign(body, additionalFields);
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
responseData = await zohoApiRequest.call(this, 'POST', '/deals', body);
|
|
|
|
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// deal: delete
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const dealId = this.getNodeParameter('dealId', i);
|
|
|
|
|
|
|
|
responseData = await zohoApiRequest.call(this, 'DELETE', `/deals/${dealId}`);
|
|
|
|
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// deal: get
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const dealId = this.getNodeParameter('dealId', i);
|
|
|
|
|
|
|
|
responseData = await zohoApiRequest.call(this, 'GET', `/deals/${dealId}`);
|
|
|
|
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// deal: getAll
|
|
|
|
// ----------------------------------------
|
|
|
|
|
2021-05-07 01:18:10 -07:00
|
|
|
responseData = await handleListing.call(this, 'GET', '/deals');
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// deal: update
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {};
|
|
|
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
|
|
|
|
|
|
if (Object.keys(updateFields).length) {
|
|
|
|
Object.assign(body, updateFields);
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
const dealId = this.getNodeParameter('dealId', i);
|
|
|
|
|
|
|
|
responseData = await zohoApiRequest.call(this, 'PUT', `/deals/${dealId}`, body);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (resource === 'invoice') {
|
|
|
|
|
|
|
|
// **********************************************************************
|
|
|
|
// invoice
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
// https://www.zoho.com/crm/developer/docs/api/v2/invoices-response.html
|
|
|
|
|
|
|
|
if (operation === 'create') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// invoice: create
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {
|
|
|
|
Product_Details: this.getNodeParameter('Product_Details', i),
|
|
|
|
Subject: this.getNodeParameter('Subject', i),
|
|
|
|
};
|
|
|
|
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
|
|
|
|
|
|
if (Object.keys(additionalFields).length) {
|
|
|
|
Object.assign(body, adjustInvoiceFields(additionalFields));
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
responseData = await zohoApiRequest.call(this, 'POST', '/invoices', body);
|
|
|
|
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// invoice: delete
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const invoiceId = this.getNodeParameter('invoiceId', i);
|
|
|
|
|
|
|
|
const endpoint = `/invoices/${invoiceId}`;
|
|
|
|
responseData = await zohoApiRequest.call(this, 'DELETE', endpoint);
|
|
|
|
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// invoice: get
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const invoiceId = this.getNodeParameter('invoiceId', i);
|
|
|
|
|
|
|
|
const endpoint = `/invoices/${invoiceId}`;
|
|
|
|
responseData = await zohoApiRequest.call(this, 'GET', endpoint);
|
|
|
|
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// invoice: getAll
|
|
|
|
// ----------------------------------------
|
|
|
|
|
2021-05-07 01:18:10 -07:00
|
|
|
responseData = await handleListing.call(this, 'GET', '/invoices');
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// invoice: update
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {};
|
|
|
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
|
|
|
|
|
|
if (Object.keys(updateFields).length) {
|
|
|
|
Object.assign(body, adjustInvoiceFields(updateFields));
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
const invoiceId = this.getNodeParameter('invoiceId', i);
|
|
|
|
|
|
|
|
const endpoint = `/invoices/${invoiceId}`;
|
|
|
|
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (resource === 'lead') {
|
|
|
|
|
|
|
|
// **********************************************************************
|
|
|
|
// lead
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
// https://www.zoho.com/crm/developer/docs/api/v2/leads-response.html
|
|
|
|
|
|
|
|
if (operation === 'create') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// lead: create
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {
|
|
|
|
Company: this.getNodeParameter('Company', i),
|
2021-05-07 01:58:40 -07:00
|
|
|
Last_Name: this.getNodeParameter('lastName', i),
|
2021-04-29 02:56:19 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
|
|
|
|
|
|
if (Object.keys(additionalFields).length) {
|
|
|
|
Object.assign(body, adjustLeadFields(additionalFields));
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
responseData = await zohoApiRequest.call(this, 'POST', '/leads', body);
|
|
|
|
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// lead: delete
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const leadId = this.getNodeParameter('leadId', i);
|
|
|
|
|
|
|
|
responseData = await zohoApiRequest.call(this, 'DELETE', `/leads/${leadId}`);
|
|
|
|
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// lead: get
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const leadId = this.getNodeParameter('leadId', i);
|
|
|
|
|
|
|
|
responseData = await zohoApiRequest.call(this, 'GET', `/leads/${leadId}`);
|
|
|
|
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// lead: getAll
|
|
|
|
// ----------------------------------------
|
|
|
|
|
2021-05-07 01:18:10 -07:00
|
|
|
responseData = await handleListing.call(this, 'GET', '/leads');
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// lead: update
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {};
|
|
|
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
|
|
|
|
|
|
if (Object.keys(updateFields).length) {
|
|
|
|
Object.assign(body, adjustLeadFields(updateFields));
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
const leadId = this.getNodeParameter('leadId', i);
|
|
|
|
|
2020-02-15 16:23:22 -08:00
|
|
|
responseData = await zohoApiRequest.call(this, 'PUT', `/leads/${leadId}`, body);
|
2020-03-31 09:54:44 -07:00
|
|
|
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
} else if (resource === 'purchaseOrder') {
|
|
|
|
|
|
|
|
// **********************************************************************
|
|
|
|
// purchaseOrder
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
// https://www.zoho.com/crm/developer/docs/api/v2/purchase-orders-response.html
|
|
|
|
|
|
|
|
if (operation === 'create') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// purchaseOrder: create
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {
|
|
|
|
Subject: this.getNodeParameter('Subject', i),
|
2021-05-07 01:58:40 -07:00
|
|
|
Vendor_Name: this.getNodeParameter('vendorName', i),
|
2021-04-29 02:56:19 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
|
|
|
|
|
|
if (Object.keys(additionalFields).length) {
|
|
|
|
Object.assign(body, adjustPurchaseOrderFields(additionalFields));
|
2020-03-31 09:54:44 -07:00
|
|
|
}
|
|
|
|
|
2021-04-29 02:56:19 -07:00
|
|
|
responseData = await zohoApiRequest.call(this, 'POST', '/purchaseorders', body);
|
|
|
|
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// purchaseOrder: delete
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const purchaseOrderId = this.getNodeParameter('purchaseOrderId', i);
|
|
|
|
|
|
|
|
const endpoint = `/purchaseorders/${purchaseOrderId}`;
|
|
|
|
responseData = await zohoApiRequest.call(this, 'DELETE', endpoint);
|
|
|
|
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// purchaseOrder: get
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const purchaseOrderId = this.getNodeParameter('purchaseOrderId', i);
|
|
|
|
|
|
|
|
const endpoint = `/purchaseorders/${purchaseOrderId}`;
|
|
|
|
responseData = await zohoApiRequest.call(this, 'GET', endpoint);
|
|
|
|
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// purchaseOrder: getAll
|
|
|
|
// ----------------------------------------
|
|
|
|
|
2021-05-07 01:18:10 -07:00
|
|
|
responseData = await handleListing.call(this, 'GET', '/purchaseorders');
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// purchaseOrder: update
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {};
|
|
|
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
|
|
|
|
|
|
if (Object.keys(updateFields).length) {
|
|
|
|
Object.assign(body, adjustPurchaseOrderFields(updateFields));
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
const purchaseOrderId = this.getNodeParameter('purchaseOrderId', i);
|
|
|
|
|
|
|
|
const endpoint = `/purchaseorders/${purchaseOrderId}`;
|
|
|
|
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (resource === 'quote') {
|
|
|
|
|
|
|
|
// **********************************************************************
|
|
|
|
// quote
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
// https://www.zoho.com/crm/developer/docs/api/v2/quotes-response.html
|
|
|
|
|
|
|
|
if (operation === 'create') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// quote: create
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {
|
|
|
|
Product_Details: this.getNodeParameter('Product_Details', i),
|
|
|
|
Subject: this.getNodeParameter('Subject', i),
|
|
|
|
};
|
|
|
|
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
|
|
|
|
|
|
if (Object.keys(additionalFields).length) {
|
|
|
|
Object.assign(body, adjustQuoteFields(additionalFields));
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
responseData = await zohoApiRequest.call(this, 'POST', '/quotes', body);
|
|
|
|
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// quote: delete
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const quoteId = this.getNodeParameter('quoteId', i);
|
|
|
|
|
|
|
|
responseData = await zohoApiRequest.call(this, 'DELETE', `/quotes/${quoteId}`);
|
|
|
|
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// quote: get
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const quoteId = this.getNodeParameter('quoteId', i);
|
|
|
|
|
|
|
|
responseData = await zohoApiRequest.call(this, 'GET', `/quotes/${quoteId}`);
|
|
|
|
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// quote: getAll
|
|
|
|
// ----------------------------------------
|
|
|
|
|
2021-05-07 01:18:10 -07:00
|
|
|
responseData = await handleListing.call(this, 'GET', '/quotes');
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// quote: update
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {};
|
|
|
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
|
|
|
|
|
|
if (Object.keys(updateFields).length) {
|
|
|
|
Object.assign(body, adjustQuoteFields(updateFields));
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
const quoteId = this.getNodeParameter('quoteId', i);
|
|
|
|
|
|
|
|
responseData = await zohoApiRequest.call(this, 'PUT', `/quotes/${quoteId}`, body);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (resource === 'salesOrder') {
|
|
|
|
|
|
|
|
// **********************************************************************
|
|
|
|
// salesOrder
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
// https://www.zoho.com/crm/developer/docs/api/v2/sales-orders-response.html
|
|
|
|
|
|
|
|
if (operation === 'create') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// salesOrder: create
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {
|
|
|
|
Account_Name: this.getNodeParameter('Account_Name', i),
|
|
|
|
Subject: this.getNodeParameter('Subject', i),
|
|
|
|
};
|
|
|
|
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
|
|
|
|
|
|
if (Object.keys(additionalFields).length) {
|
|
|
|
Object.assign(body, adjustSalesOrderFields(additionalFields));
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
responseData = await zohoApiRequest.call(this, 'POST', '/salesorders', body);
|
|
|
|
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// salesOrder: delete
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const salesOrderId = this.getNodeParameter('salesOrderId', i);
|
|
|
|
|
|
|
|
const endpoint = `/salesorders/${salesOrderId}`;
|
|
|
|
responseData = await zohoApiRequest.call(this, 'DELETE', endpoint);
|
|
|
|
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// salesOrder: get
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const salesOrderId = this.getNodeParameter('salesOrderId', i);
|
|
|
|
|
|
|
|
const endpoint = `/salesorders/${salesOrderId}`;
|
|
|
|
responseData = await zohoApiRequest.call(this, 'GET', endpoint);
|
|
|
|
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// salesOrder: getAll
|
|
|
|
// ----------------------------------------
|
|
|
|
|
2021-05-07 01:18:10 -07:00
|
|
|
responseData = await handleListing.call(this, 'GET', '/salesorders');
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// salesOrder: update
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const body: IDataObject = {};
|
|
|
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
|
|
|
|
|
|
if (Object.keys(updateFields).length) {
|
|
|
|
Object.assign(body, adjustSalesOrderFields(updateFields));
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
const salesOrderId = this.getNodeParameter('salesOrderId', i);
|
|
|
|
|
|
|
|
const endpoint = `/salesorders/${salesOrderId}`;
|
|
|
|
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
|
|
|
|
|
2020-02-15 16:23:22 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
2020-02-12 07:04:43 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
|
|
|
Array.isArray(responseData)
|
|
|
|
? returnData.push(...responseData)
|
|
|
|
: returnData.push(responseData);
|
|
|
|
|
2020-02-12 07:04:43 -08:00
|
|
|
}
|
2021-04-29 02:56:19 -07:00
|
|
|
|
2020-02-12 07:04:43 -08:00
|
|
|
return [this.helpers.returnJsonArray(returnData)];
|
|
|
|
}
|
|
|
|
}
|