fix(HTTP Request Node): Support for dot notation in JSON body

This commit is contained in:
Michael Kret
2023-03-31 19:31:03 +03:00
committed by GitHub
parent d87736103d
commit b29cf9a249
4 changed files with 82 additions and 7 deletions

View File

@@ -10,14 +10,17 @@ import type {
INodeTypeDescription,
JsonObject,
} from 'n8n-workflow';
import { BINARY_ENCODING, jsonParse, NodeApiError, NodeOperationError, sleep } from 'n8n-workflow';
import type { OptionsWithUri } from 'request-promise-native';
import type { IAuthDataSanitizeKeys } from '../GenericFunctions';
import type { BodyParameter, IAuthDataSanitizeKeys } from '../GenericFunctions';
import {
binaryContentTypes,
getOAuth2AdditionalParameters,
prepareRequestBody,
replaceNullValues,
sanitizeUiMessage,
} from '../GenericFunctions';
@@ -35,7 +38,7 @@ export class HttpRequestV3 implements INodeType {
this.description = {
...baseDescription,
subtitle: '={{$parameter["method"] + ": " + $parameter["url"]}}',
version: 3,
version: [3, 4],
defaults: {
name: 'HTTP Request',
color: '#2200DD',
@@ -879,6 +882,7 @@ export class HttpRequestV3 implements INodeType {
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const nodeVersion = this.getNode().typeVersion;
const fullResponseProperties = ['body', 'headers', 'statusCode', 'statusMessage'];
@@ -960,9 +964,11 @@ export class HttpRequestV3 implements INodeType {
const sendBody = this.getNodeParameter('sendBody', itemIndex, false) as boolean;
const bodyContentType = this.getNodeParameter('contentType', itemIndex, '') as string;
const specifyBody = this.getNodeParameter('specifyBody', itemIndex, '') as string;
const bodyParameters = this.getNodeParameter('bodyParameters.parameters', itemIndex, []) as [
{ name: string; value: string },
];
const bodyParameters = this.getNodeParameter(
'bodyParameters.parameters',
itemIndex,
[],
) as BodyParameter[];
const jsonBodyParameter = this.getNodeParameter('jsonBody', itemIndex, '') as string;
const body = this.getNodeParameter('body', itemIndex, '') as string;
@@ -1094,7 +1100,12 @@ export class HttpRequestV3 implements INodeType {
// Get parameters defined in the UI
if (sendBody && bodyParameters) {
if (specifyBody === 'keypair' || bodyContentType === 'multipart-form-data') {
requestOptions.body = bodyParameters.reduce(parametersToKeyValue, {});
requestOptions.body = prepareRequestBody(
bodyParameters,
bodyContentType,
nodeVersion,
parametersToKeyValue,
);
} else if (specifyBody === 'json') {
// body is specified using JSON
if (typeof jsonBodyParameter !== 'object' && jsonBodyParameter !== null) {