I am adding the code here. Feel free to test it and make a PR to main repo.
file: packages/nodes-base/nodes/Zoho/ZohoBooks.node.json
{
"node": "n8n-nodes-base.zohoBooks",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"categories": [
"Communication",
"Sales"
],
"resources": {
"credentialDocumentation": [
{
"url": "https://docs.n8n.io/credentials/zoho"
}
],
"primaryDocumentation": [
{
"url": ""
}
]
}
}
file: packages/nodes-base/nodes/Zoho/ZohoBooks.node.ts
import { IDataObject, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
import { IExecuteFunctions } from 'n8n-core';
import { zohoApiRequest } from './GenericFunctions';
const moment = require('moment');
export class ZohoBooks implements INodeType {
description: INodeTypeDescription = {
displayName: 'Zoho Book',
name: 'zohoBooks',
icon: 'file:zohoCrm.png',
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
group: ['input'],
version: 1,
description: 'Consume Zoho Books API.',
defaults: {
name: 'Zoho Books',
color: '#CE2232',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'zohoOAuth2Api',
required: true,
},
],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
options: [
{
name: 'Invoice',
value: 'invoice',
},
],
default: 'invoice',
description: 'The resource to operate on.',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'invoice',
],
},
},
options: [
{
name: 'Get All',
value: 'getAll',
description: 'List all the invoices',
},
{
name: 'Get an invoice',
value: 'get',
description: 'Get one invoice',
},
],
default: 'getAll',
description: 'The operation to perform.',
},
{
displayName: 'Organization Id',
name: 'organization_id',
type: 'string',
default: '',
description: 'Organization id to get data from.',
required: true,
},
{
displayName: 'Date',
name: 'dateOfInvoice',
type: 'dateTime',
default: '',
description: 'Date of invoices which you want to retrieve.',
displayOptions: {
show: {
operation: [
'getAll',
],
},
},
},
{
displayName: 'Invoice Id',
name: 'invoice_id',
type: 'string',
default: '',
description: 'Invoice id which you want to get.',
displayOptions: {
show: {
operation: [
'get',
],
},
},
},
],
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
let returnData: IDataObject[] = [];
const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string;
const organizationId = this.getNodeParameter('organization_id', 0) as string;
if (resource === 'invoice') {
if (operation === 'getAll') {
const uri = `https://books.zoho.in/api/v3/invoices`;
let hasMore = true;
const dateOfInvoice = this.getNodeParameter('dateOfInvoice', 0) as string;
const qs: IDataObject = {
organization_id: organizationId,
date: dateOfInvoice ? moment(dateOfInvoice).format('YYYY-MM-DD') : dateOfInvoice,
page: 1,
per_page: 200,
};
while (hasMore) {
const { invoices, page_context: { has_more_page } } = await zohoApiRequest.call(this, 'GET', '', {}, qs, uri);
returnData = [...returnData, ...invoices];
hasMore = has_more_page;
if (typeof (qs.page) === 'number') {
qs.page++;
}
}
} else if (operation === 'get') {
const invoiceId = this.getNodeParameter('invoice_id', 0) as string;
const qs: IDataObject = {
organization_id: organizationId,
};
const uri = `https://books.zoho.in/api/v3/invoices/${invoiceId}`;
returnData = await zohoApiRequest.call(this, 'GET', '', {}, qs, uri);
}
}
return [this.helpers.returnJsonArray(returnData)];
}
}
add the "dist/nodes/Zoho/ZohoBooks.node.js", in packages/nodes-base/package.json and then you should be good to go.
If there is any error feel free to reach out to me. do mention me (github username vasani-arpit) in PR if you make one so that I can check/review.