Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(HTTP Request Node): add option for raw json header & query #4408

Merged
merged 4 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

122 changes: 117 additions & 5 deletions packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,35 @@ export class HttpRequestV3 implements INodeType {
noDataExpression: true,
description: 'Whether the request has query params or not',
},
{
displayName: 'Specify Query Parameters',
name: 'specifyQuery',
type: 'options',
displayOptions: {
show: {
sendQuery: [true],
},
},
options: [
{
name: 'Using Fields Below',
value: 'keypair',
},
{
name: 'Using JSON',
value: 'json',
},
],
default: 'keypair',
},
{
displayName: 'Query Parameters',
name: 'queryParameters',
type: 'fixedCollection',
displayOptions: {
show: {
sendQuery: [true],
specifyQuery: ['keypair'],
},
},
typeOptions: {
Expand Down Expand Up @@ -186,6 +208,18 @@ export class HttpRequestV3 implements INodeType {
},
],
},
{
displayName: 'JSON',
name: 'jsonQuery',
type: 'json',
displayOptions: {
show: {
sendQuery: [true],
specifyQuery: ['json'],
},
},
default: '',
},
{
displayName: 'Send Headers',
name: 'sendHeaders',
Expand All @@ -194,13 +228,35 @@ export class HttpRequestV3 implements INodeType {
noDataExpression: true,
description: 'Whether the request has headers or not',
},
{
displayName: 'Specify Headers',
name: 'specifyHeaders',
type: 'options',
displayOptions: {
show: {
sendHeaders: [true],
},
},
options: [
{
name: 'Using Fields Below',
value: 'keypair',
},
{
name: 'Using JSON',
value: 'json',
},
],
default: 'keypair',
},
{
displayName: 'Header Parameters',
name: 'headerParameters',
type: 'fixedCollection',
displayOptions: {
show: {
sendHeaders: [true],
specifyHeaders: ['keypair'],
},
},
typeOptions: {
Expand Down Expand Up @@ -236,6 +292,18 @@ export class HttpRequestV3 implements INodeType {
},
],
},
{
displayName: 'JSON',
name: 'jsonHeaders',
type: 'json',
displayOptions: {
show: {
sendHeaders: [true],
specifyHeaders: ['json'],
},
},
default: '',
},
{
displayName: 'Send Body',
name: 'sendBody',
Expand Down Expand Up @@ -865,6 +933,9 @@ export class HttpRequestV3 implements INodeType {
itemIndex,
[],
) as [{ name: string; value: string }];
const specifyQuery = this.getNodeParameter('specifyQuery', itemIndex, 'keypair') as string;
const jsonQueryParameter = this.getNodeParameter('jsonQuery', itemIndex, '') as string;

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;
Expand All @@ -880,6 +951,8 @@ export class HttpRequestV3 implements INodeType {
itemIndex,
[],
) as [{ name: string; value: string }];
const specifyHeaders = this.getNodeParameter('specifyHeaders', itemIndex, 'keypair') as string;
const jsonHeadersParameter = this.getNodeParameter('jsonHeaders', itemIndex, '') as string;

const {
redirect,
Expand Down Expand Up @@ -1053,15 +1126,54 @@ export class HttpRequestV3 implements INodeType {
}
}

// Get parameters defined in the UI
if (sendQuery && queryParameters) {
requestOptions.qs = await queryParameters.reduce(parmetersToKeyValue, Promise.resolve({}));
if (specifyQuery === 'keypair') {
requestOptions.qs = await queryParameters.reduce(
parmetersToKeyValue,
Promise.resolve({}),
);
} else if (specifyQuery === 'json') {
// query is specified using JSON
try {
JSON.parse(jsonQueryParameter);
} catch (_) {
throw new NodeOperationError(
this.getNode(),
`JSON parameter need to be an valid JSON`,
{
runIndex: itemIndex,
},
);
}

requestOptions.qs = JSON.parse(jsonQueryParameter);
}
}

// Get parameters defined in the UI
if (sendHeaders && headerParameters) {
requestOptions.headers = await headerParameters.reduce(
parmetersToKeyValue,
Promise.resolve({}),
);
if (specifyHeaders === 'keypair') {
requestOptions.headers = await headerParameters.reduce(
parmetersToKeyValue,
Promise.resolve({}),
);
} else if (specifyHeaders === 'json') {
// body is specified using JSON
try {
JSON.parse(jsonHeadersParameter);
} catch (_) {
throw new NodeOperationError(
this.getNode(),
`JSON parameter need to be an valid JSON`,
{
runIndex: itemIndex,
},
);
}

requestOptions.headers = JSON.parse(jsonHeadersParameter);
}
}

if (autoDetectResponseFormat || responseFormat === 'file') {
Expand Down