diff --git a/packages/nodes-base/nodes/Zoho/GenericFunctions.ts b/packages/nodes-base/nodes/Zoho/GenericFunctions.ts index 954501f67a794..4351ab1c4cc83 100644 --- a/packages/nodes-base/nodes/Zoho/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Zoho/GenericFunctions.ts @@ -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); @@ -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); } } @@ -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) }; + } }); }; diff --git a/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts b/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts index 6978b6eb6efb4..62dd144715ffd 100644 --- a/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts +++ b/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts @@ -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);