I have created a Coda pack to connect to my N8N webhook on a server. I want to do is send POST request from Coda.
Issue I am facing is sometimes the POST request goes through successfully, but many a times it fails. (Success Ratio is roughly 1 in 10).
What is the issue in my pack code / can I make it more reliable?
pack.addNetworkDomain('my server domain eg. xyz.abc');
pack.addFormula({
name: "POST",
description: "Send a POST request to a specified URL with a JSON payload.",
isAction: true,
parameters: [
coda.makeParameter({ type: coda.ParameterType.String, name: "url", description: "The full URL of the request." }),
coda.makeParameter({ type: coda.ParameterType.String, name: "payload", description: "A payload object created with an Object() formula." }),
],
resultType: coda.ValueType.String,
execute: async function ([url, payload], context) {
const headers: { [key: string]: string } = {
"Content-Type": "application/json",
};
const request: coda.FetchRequest = {
url,
method: "POST",
headers,
body: payload,
};
let response = await context.fetcher.fetch(request);
if (response.status >= 200 && response.status < 300) {
return response.body;
}
return `Error: ${response.status}`;
},
});
I am getting following error:
Error: 13 INTERNAL: FetchError: request to https://my-n8n-webhook failed, reason:
Stack Trace: at process.processTicksAndRejections (node:internal/process/task_queues:85:11)