How to send POST request reliably from Coda

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)

2 Likes

@Piyush_Pallav have you tried asking an LLM? I find Grok to be quite good with code. See:
https://grok.com/share/bGVnYWN5_e626da78-73df-4ca5-b52c-3feaa4beaf78

Havent tried Grok specifically, but I did use some bit of LLM for tuning.

Initially I extensively tried LLMs to generate the pack but what I observed was since there is not a lot of detailed documentation available for Coda and API call, most of the results just gave me code which threw random logics which the Coda pack generator did not understand.

Also, I am not a proper programmer so I am finding it much more difficult.

Use windsurf, and share the links to the coda SDK and the API you’re using. Worked pretty well for me.

Sure you’re already using the Coda SDK to model from, but worth copy and pasting their functional post calls to get you started.

If you want to hit a specific endpoint in an api provide an example of functional code from the documentation and explain you want to hit it.

You will need to be able to understand what is written in the code, but you can ask windsurf to explain it to you line by line, or add comments to the code explaining it.

Based on your error it seems you’re putting too many tasks in a queue, which could be an error on the side of your n8n server as I don’t see any immediate problems on this side in terms of creating a loop or something which makes more requests.

Also depends on how you are sending it from coda; if you’re using a formula in coda of some form, you need to look into how that’s structured as well - not just the pack code, as this may be creating additional requests.