mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
fix(Zoho CRM Node): Fix issue with Sales Order not updating (#6959)
This commit is contained in:
parent
5c6cccd4fa
commit
fd800b674b
|
@ -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) };
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue