Skip to content

Commit

Permalink
fix(Zoho CRM Node): Fix issue with Sales Order not updating (#6959)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joffcom authored Sep 11, 2023
1 parent 5c6cccd commit fd800b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
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 {
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

0 comments on commit fd800b6

Please sign in to comment.