diff --git a/packages/nodes-base/nodes/Mindee/GenericFunctions.ts b/packages/nodes-base/nodes/Mindee/GenericFunctions.ts index 3c095c411512a..f19d46c6b515d 100644 --- a/packages/nodes-base/nodes/Mindee/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Mindee/GenericFunctions.ts @@ -101,6 +101,20 @@ export function cleanData(document: IDataObject) { newData.currency = data.currency; //@ts-ignore newData.locale = data.value; + } else if (key === 'line_items') { + const lineItems: IDataObject[] = []; + for (const lineItem of data as IDataObject[]) { + lineItems.push({ + description: lineItem.description, + product_code: lineItem.product_code, + quantity: lineItem.quantity, + tax_amount: lineItem.tax_amount, + tax_rate: lineItem.tax_rate, + total_amount: lineItem.total_amount, + unit_price: lineItem.unit_price, + }); + } + newData[key] = lineItems; } else { newData[key] = //@ts-ignore diff --git a/packages/nodes-base/nodes/Mindee/Mindee.node.ts b/packages/nodes-base/nodes/Mindee/Mindee.node.ts index c7b2e79f484eb..d42b1f8f8c06a 100644 --- a/packages/nodes-base/nodes/Mindee/Mindee.node.ts +++ b/packages/nodes-base/nodes/Mindee/Mindee.node.ts @@ -15,7 +15,7 @@ export class Mindee implements INodeType { name: 'mindee', icon: 'file:mindee.svg', group: ['input'], - version: [1, 2], + version: [1, 2, 3], subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', description: 'Consume Mindee API', defaults: { @@ -63,9 +63,13 @@ export class Mindee implements INodeType { name: '3', value: 3, }, + { + name: '4', + value: 4, + }, ], default: 1, - description: 'Whether to return all results or only up to a given limit', + description: 'Which Mindee API Version to use', }, { displayName: 'API Version', @@ -86,9 +90,40 @@ export class Mindee implements INodeType { name: '3', value: 3, }, + { + name: '4', + value: 4, + }, ], default: 3, - description: 'Whether to return all results or only up to a given limit', + description: 'Which Mindee API Version to use', + }, + { + displayName: 'API Version', + name: 'apiVersion', + type: 'options', + isNodeSetting: true, + displayOptions: { + show: { + '@version': [3], + }, + }, + options: [ + { + name: '1', + value: 1, + }, + { + name: '3', + value: 3, + }, + { + name: '4', + value: 4, + }, + ], + default: 4, + description: 'Which Mindee API Version to use', }, { displayName: 'Resource', @@ -201,13 +236,32 @@ export class Mindee implements INodeType { }, }, ); + } else if (version === 4) { + endpoint = '/expense_receipts/v4/predict'; + responseData = await mindeeApiRequest.call( + this, + 'POST', + endpoint, + {}, + {}, + { + formData: { + document: { + value: dataBuffer, + options: { + filename: binaryData.fileName, + }, + }, + }, + }, + ); } if (!rawData) { if (version === 1) { responseData = cleanDataPreviousApiVersions( responseData.predictions as IDataObject[], ); - } else if (version === 3) { + } else if (version === 3 || version === 4) { responseData = cleanData(responseData.document as IDataObject); } } @@ -260,6 +314,25 @@ export class Mindee implements INodeType { }, }, ); + } else if (version === 4) { + endpoint = '/invoices/v4/predict'; + responseData = await mindeeApiRequest.call( + this, + 'POST', + endpoint, + {}, + {}, + { + formData: { + document: { + value: dataBuffer, + options: { + filename: binaryData.fileName, + }, + }, + }, + }, + ); } else { throw new NodeOperationError(this.getNode(), 'Invalid API version'); } @@ -268,7 +341,7 @@ export class Mindee implements INodeType { responseData = cleanDataPreviousApiVersions( responseData.predictions as IDataObject[], ); - } else if (version === 3) { + } else if (version === 3 || version === 4) { responseData = cleanData(responseData.document as IDataObject); } }