Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Zoho CRM Node): Fix issue with Sales Order not updating #6959

25 changes: 18 additions & 7 deletions packages/nodes-base/nodes/Zoho/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import type {

export function throwOnErrorStatus(
this: IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions,
responseData: { data?: Array<{ status: string; message: string }> },
responseData: {
data?: Array<{ status: string; message: string }>;
},
) {
if (responseData?.data?.[0].status === 'error') {
throw new NodeOperationError(this.getNode(), responseData as Error);
Expand Down Expand Up @@ -69,14 +71,18 @@ export async function zohoApiRequest(

try {
const responseData = await this.helpers.requestOAuth2?.call(this, 'zohoOAuth2Api', options);

if (responseData === undefined) return [];

throwOnErrorStatus.call(this, responseData as IDataObject);

return responseData;
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
const args = error.cause?.data
? {
message: error.cause.data.message || 'The Zoho API returned an error.',
description: JSON.stringify(error.cause.data, null, 2),
}
: undefined;
throw new NodeApiError(this.getNode(), error as JsonObject, args);
}
}

Expand Down Expand Up @@ -161,13 +167,18 @@ const omit = (propertyToOmit: string, { [propertyToOmit]: _, ...remainingObject
/**
* Place a product ID at a nested position in a product details field.
*/
export const adjustProductDetails = (productDetails: ProductDetails) => {
export const adjustProductDetails = (productDetails: ProductDetails, operation?: string) => {
return productDetails.map((p) => {
return {
...omit('product', p),
const adjustedProduct = {
product: { id: p.id },
quantity: p.quantity || 1,
};

if (operation === 'upsert') {
return { ...adjustedProduct, ...omit('id', p) };
} else {
Joffcom marked this conversation as resolved.
Show resolved Hide resolved
return { ...adjustedProduct, ...omit('product', p) };
}
});
};

Expand Down
2 changes: 1 addition & 1 deletion packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ export class ZohoCrm implements INodeType {
const body: IDataObject = {
Account_Name: { id: this.getNodeParameter('accountId', i) },
Subject: this.getNodeParameter('subject', i),
Product_Details: adjustProductDetails(productDetails),
Product_Details: adjustProductDetails(productDetails, 'upsert'),
};

const additionalFields = this.getNodeParameter('additionalFields', i);
Expand Down
Loading