I have a flow where I have the built-in app and a NodeJS script both trying to use Webhooks.
Here's the NodeJS Script I'm using:
According to this, I should be able to send data to: https://{MYHOST}:51088/scripting/testconst fs = require('fs-extra');
const os = require('os');
async function flowStartTriggered(s, flowElement) {
try {
await s.httpRequestSubscribe(HttpRequest.Method.POST, '/test');
}
catch (error) {
await flowElement.failProcess("Failed to subscribe to the request %1", error.message);
}
}
async function httpRequestTriggeredSync(request, args, response, s) {
let requestBody = JSON.parse(request.getBodyAsString());
let requestHeaders = request.headers;
await flowElement.log(LogLevel.Warning, `Request Body: ${JSON.stringify(requestBody)}`);
await flowElement.log(LogLevel.Warning, `Request Headers: ${JSON.stringify(requestHeaders)}`);
await flowElement.log(LogLevel.Warning, `Response Object Names: ${JSON.stringify(Object.getOwnPropertyNames(response))}`);
await flowElement.log(LogLevel.Warning, `Response Object Descriptors: ${JSON.stringify(Object.getOwnPropertyDescriptors(response))}`);
response.setStatusCode(200);
response.setBody(Buffer.from({'status':'true'}));
return;
}
async function httpRequestTriggeredAsync(request, args, s, flowElement) {
let requestBody = JSON.parse(request.getBodyAsString());
let tmpFileName = `${await os.tmpdir()}/tmpwebhookfile.json'`;
await fs.writeJson(tmpFileName, requestBody);
let tmpJob = await flowElement.createJob(tmpFileName);
await tmpJob.sendToSingle();
await fs.remove(tmpJob);
}
When I start the script, I see the following text in the message board on the switch server:
08:43:32 - WebhookFlowTest - Webhook - Subscribed to requests for the path /testApp
08:43:32 - WebhookFlowTest - Webhook - the Request Method is: POST
08:43:32 - WebhookFlowTest - Webhook - the Protocol Type is : HTTPS
08:43:32 - WebhookFlowTest - Webhook - The notification to 'ws://127.0.0.1:55095/api/v1/process' has been sent successfully. Waiting for the "processing finished" response...
08:43:32 - WebhookFlowTest - NodeJSWebhookTest - The notification to 'ws://127.0.0.1:55095/api/v1/process' has been sent successfully. Waiting for the "processing finished" response...
Using Postman to send and receive responses, the built-in Switch Webhook App will receive the webhook, create a JSON file and place it in a folder, it then returns the message:
{"status": "true"}
The NodeJSWebhookTest returns:
{
"status": false,
"error": "Cannot send webhook response: TypeError [ERR_INVALID_URL]: Invalid URL"
}
Yet, if I send the data to a wrong URL, I get:
{
"status": false,
"error": "Subscription cannot be found."
}
The app in Switch says the webhook is Version 7.
I am running Fall 2022 version of Switch. I just upgraded this week.
This webhook WAS WORKING in Spring 2022.