From 3029178eeb7a2ca9ee30bc16cf0cb6f17b431913 Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Tue, 3 Aug 2021 22:39:01 +0200 Subject: [PATCH 1/2] add headers input in outgoing webhook automation step --- .../server/src/automations/steps/outgoingWebhook.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/server/src/automations/steps/outgoingWebhook.js b/packages/server/src/automations/steps/outgoingWebhook.js index 269e075018..363190bf3f 100644 --- a/packages/server/src/automations/steps/outgoingWebhook.js +++ b/packages/server/src/automations/steps/outgoingWebhook.js @@ -27,6 +27,7 @@ module.exports.definition = { requestMethod: "POST", url: "http://", requestBody: "{}", + headers: "{}", }, schema: { inputs: { @@ -45,6 +46,11 @@ module.exports.definition = { title: "JSON Body", customType: "wide", }, + headers: { + type: "string", + title: "Headers", + customType: "wide", + }, }, required: ["requestMethod", "url"], }, @@ -65,7 +71,7 @@ module.exports.definition = { } module.exports.run = async function ({ inputs }) { - let { requestMethod, url, requestBody } = inputs + let { requestMethod, url, requestBody, headers } = inputs if (!url.startsWith("http")) { url = `http://${url}` } @@ -84,6 +90,10 @@ module.exports.run = async function ({ inputs }) { request.headers = { "Content-Type": "application/json", } + + if (headers && headers.length !== 0) { + request.headers = { ...request.headers, ...JSON.parse(headers) } + } } try { From 81b4f8f5d43cea0721141a366e7ab2ae211605af Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Tue, 3 Aug 2021 22:53:18 +0200 Subject: [PATCH 2/2] add try/catch block around JSON.parse, since user input can be incorrect formatted string --- packages/server/src/automations/steps/outgoingWebhook.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/server/src/automations/steps/outgoingWebhook.js b/packages/server/src/automations/steps/outgoingWebhook.js index 363190bf3f..c1edde7b4e 100644 --- a/packages/server/src/automations/steps/outgoingWebhook.js +++ b/packages/server/src/automations/steps/outgoingWebhook.js @@ -92,7 +92,12 @@ module.exports.run = async function ({ inputs }) { } if (headers && headers.length !== 0) { - request.headers = { ...request.headers, ...JSON.parse(headers) } + try { + const customHeaders = JSON.parse(headers) + request.headers = { ...request.headers, ...customHeaders } + } catch (err) { + console.error(err) + } } }