From 8dbe6159d04c963e7858d31d64721ddc0911ea36 Mon Sep 17 00:00:00 2001 From: Michael Kret <88898367+michael-radency@users.noreply.github.com> Date: Wed, 18 Jan 2023 15:31:39 +0200 Subject: [PATCH] fix(HTTP Request Node): Response format to text is ignored for JSON responses --- .../nodes/HttpRequest/V3/HttpRequestV3.node.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts b/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts index b0d92032cc..83d3fdfde6 100644 --- a/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts +++ b/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts @@ -1,6 +1,7 @@ import { IExecuteFunctions } from 'n8n-core'; import { + IBinaryKeyData, IDataObject, INodeExecutionData, INodeType, @@ -21,6 +22,13 @@ import { replaceNullValues, sanitizeUiMessage, } from '../GenericFunctions'; + +function toText(data: T) { + if (typeof data === 'object' && data !== null) { + return JSON.stringify(data); + } + return data; +} export class HttpRequestV3 implements INodeType { description: INodeTypeDescription; @@ -1289,12 +1297,10 @@ export class HttpRequestV3 implements INodeType { } } - // @ts-ignore const promisesResponses = await Promise.allSettled(requestPromises); let response: any; for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { - // @ts-ignore response = promisesResponses.shift(); if (response!.status !== 'fulfilled') { @@ -1374,8 +1380,7 @@ export class HttpRequestV3 implements INodeType { // Create a shallow copy of the binary data so that the old // data references which do not get changed still stay behind // but the incoming data does not get changed. - // @ts-ignore - Object.assign(newItem.binary, items[itemIndex].binary); + Object.assign(newItem.binary as IBinaryKeyData, items[itemIndex].binary); } const fileName = url.split('/').pop(); @@ -1415,7 +1420,7 @@ export class HttpRequestV3 implements INodeType { const returnItem: IDataObject = {}; for (const property of fullReponseProperties) { if (property === 'body') { - returnItem[outputPropertyName] = response![property]; + returnItem[outputPropertyName] = toText(response![property]); continue; } @@ -1430,7 +1435,7 @@ export class HttpRequestV3 implements INodeType { } else { returnItems.push({ json: { - [outputPropertyName]: response, + [outputPropertyName]: toText(response), }, pairedItem: { item: itemIndex,