<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alec Asgari</title>
    <description>The latest articles on DEV Community by Alec Asgari (@alecasgari).</description>
    <link>https://dev.to/alecasgari</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4208566%2Ff18c141f-26b7-478a-a63f-917620372482.png</url>
      <title>DEV Community: Alec Asgari</title>
      <link>https://dev.to/alecasgari</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alecasgari"/>
    <language>en</language>
    <item>
      <title>How I keep n8n workflows reliable when third-party APIs fail</title>
      <dc:creator>Alec Asgari</dc:creator>
      <pubDate>Sat, 14 Nov 2026 11:41:14 +0000</pubDate>
      <link>https://dev.to/alecasgari/how-i-keep-n8n-workflows-reliable-when-third-party-apis-fail-fke</link>
      <guid>https://dev.to/alecasgari/how-i-keep-n8n-workflows-reliable-when-third-party-apis-fail-fke</guid>
      <description>&lt;p&gt;Most n8n workflows I review fail in the same unglamorous way. The happy path works in a test run. Then a payment API times out, a CRM returns a 429, or a webhook is delivered twice, and the workflow either stops mid-way or writes the same record twice. The business only notices when a customer is billed twice, or when a lead never arrives.&lt;/p&gt;

&lt;p&gt;I have spent 16 years in IT, the last five in Dubai, building and reviewing automation for small teams. Reliability is a design choice, not a setting you flip on later. Below is the pattern I use when a workflow has to talk to third-party APIs and still be safe to rerun.&lt;/p&gt;

&lt;h2&gt;
  
  
  The three failure modes that actually matter
&lt;/h2&gt;

&lt;p&gt;It helps to stop thinking in “success versus error” and start thinking in three buckets.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transient failures&lt;/strong&gt; are timeouts, 502/503 responses, and rate limits. A retry, after a pause, often works. If you retry immediately and without a limit, you can make the rate limit worse.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Permanent failures&lt;/strong&gt; are 401s, 404s, schema changes, and validation errors. Retrying these is a waste of time and can lock an account or fill an error log. These should go to a human, with the payload preserved.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Partial completion&lt;/strong&gt; is the dangerous one. The CRM contact was created, then the invoice call failed. Or the invoice was created, then the confirmation email failed. A naive retry of the whole workflow creates a duplicate. This is how “simple” automations quietly damage operations.&lt;/p&gt;

&lt;p&gt;If a workflow can create, charge, email, or update a record, it needs an answer for all three.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design the workflow as steps with a recorded outcome
&lt;/h2&gt;

&lt;p&gt;I no longer build long linear chains that assume every node succeeds. Each meaningful step should:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check whether it has already been done.&lt;/li&gt;
&lt;li&gt;Do the work, or skip it if the record already exists.&lt;/li&gt;
&lt;li&gt;Store the external ID or a status flag.&lt;/li&gt;
&lt;li&gt;Only then move on.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A Google Sheet, a row in Postgres, or a record in your CRM can be the source of truth. The workflow is not the source of truth; the data it writes is. When n8n restarts, or a webhook is replayed, the workflow should read that state and continue from the unfinished step, not from the beginning.&lt;/p&gt;

&lt;p&gt;A practical layout looks like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Inbound&lt;/strong&gt;: webhook or schedule, with a unique key (form ID, order ID, email plus date, or a UUID you generate once and persist).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Load or create the job record&lt;/strong&gt;: one row per business event, with fields such as &lt;code&gt;status&lt;/code&gt;, &lt;code&gt;crm_id&lt;/code&gt;, &lt;code&gt;invoice_id&lt;/code&gt;, and &lt;code&gt;last_error&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Branch on status&lt;/strong&gt;: “new”, “crm_done”, “invoice_done”, “notified”, “failed_permanent”.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do only the next unfinished step&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write the result back&lt;/strong&gt; before calling the next API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is more work than a demo workflow, and it is the difference between a tool you trust and a tool you babysit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Retries need a budget, not hope
&lt;/h2&gt;

&lt;p&gt;n8n can continue on fail, and it can retry. Those features are useful only with rules.&lt;/p&gt;

&lt;p&gt;For transient errors I use a short retry budget: a few attempts, a delay between them, and a clear stop. I log the HTTP status and a truncated body. I do not retry forever, or on every status code.&lt;/p&gt;

&lt;p&gt;For permanent errors I skip retries and write the payload to a dead-letter place: a dedicated sheet tab, a table, or a Telegram message that includes the job ID. “Continue on fail” without that record is how work disappears.&lt;/p&gt;

&lt;p&gt;I also keep retries close to the failing node. Wrapping an entire 20-node workflow in one blanket retry is how you get duplicate side effects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make every create operation idempotent
&lt;/h2&gt;

&lt;p&gt;If the API supports an idempotency key, use it. Many payment and billing APIs do. Send the same key on a retry and the provider should return the original result instead of a second charge.&lt;/p&gt;

&lt;p&gt;If the API does not support that, build your own check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Search for an existing contact by email before creating one.&lt;/li&gt;
&lt;li&gt;Store the external ID on your job record the moment you get it.&lt;/li&gt;
&lt;li&gt;On retry, if &lt;code&gt;crm_id&lt;/code&gt; is already present, skip the create node.&lt;/li&gt;
&lt;li&gt;For emails, store a &lt;code&gt;notified_at&lt;/code&gt; timestamp and refuse to send twice.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The unique key must come from the business event, not from the time n8n happened to run. Webhooks are often delivered more than once, and a queue retry will run the same job again. That is normal. The workflow has to be safe under those conditions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Alert on unresolved work, not on every handled retry
&lt;/h2&gt;

&lt;p&gt;A noisy Telegram or Slack channel trains people to ignore it. I alert when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A job sits in a failed state after the retry budget is used up.&lt;/li&gt;
&lt;li&gt;A job is older than a threshold and still not in a terminal status.&lt;/li&gt;
&lt;li&gt;An authentication error appears (these usually mean a token expired, and every job will fail until someone fixes it).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I do not alert on the first timeout that later succeeds. I do keep a daily digest of jobs that needed a retry, because a rising count is an early warning that a vendor is degrading.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to test before the workflow goes live
&lt;/h2&gt;

&lt;p&gt;Before I trust a workflow with real customers, I run a short set of ugly tests:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replay the same webhook twice, immediately.&lt;/li&gt;
&lt;li&gt;Kill the workflow after the first successful create, then run it again.&lt;/li&gt;
&lt;li&gt;Force a 429 or a timeout on one node and confirm the job resumes without a duplicate.&lt;/li&gt;
&lt;li&gt;Revoke a token and confirm the alert is clear.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If those four tests pass, the workflow is usually safe enough for a small team. If they have never been tried, I assume it will fail in production.&lt;/p&gt;

&lt;p&gt;I also prefer fewer well-owned workflows over a large pile of quick zaps. Reliability work does not scale linearly with the number of automations.&lt;/p&gt;

&lt;p&gt;The same ideas sit behind the n8n work I publish at &lt;a href="https://alecasgari.com/services/n8n-automation" rel="noopener noreferrer"&gt;https://alecasgari.com/services/n8n-automation&lt;/a&gt;. If you are comparing tools rather than designing a specific workflow, I also wrote a practical comparison at &lt;a href="https://alecasgari.com/blog/n8n-vs-make-vs-zapier" rel="noopener noreferrer"&gt;https://alecasgari.com/blog/n8n-vs-make-vs-zapier&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Reliability will not make a messy process elegant. It will stop a useful process from creating duplicate invoices and missing leads. That is the bar I set before an automation runs unattended.&lt;/p&gt;

&lt;p&gt;I am Alec Asgari. If you want a second pair of eyes on a workflow that already fails in one of these ways, write to &lt;a href="mailto:hello@alecasgari.com"&gt;hello@alecasgari.com&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>n8n</category>
      <category>automation</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How I automate lead intake with n8n, Cloudflare Turnstile and Telegram</title>
      <dc:creator>Alec Asgari</dc:creator>
      <pubDate>Mon, 26 Oct 2026 11:26:43 +0000</pubDate>
      <link>https://dev.to/alecasgari/how-i-automate-lead-intake-with-n8n-cloudflare-turnstile-and-telegram-2mc3</link>
      <guid>https://dev.to/alecasgari/how-i-automate-lead-intake-with-n8n-cloudflare-turnstile-and-telegram-2mc3</guid>
      <description>&lt;p&gt;Most small-business websites still treat the contact form as an afterthought. A visitor fills it in, and an email lands in a shared inbox where it waits next to newsletters and invoices. Someone notices it hours later, or never. Meanwhile, half the messages are spam.&lt;/p&gt;

&lt;p&gt;When I rebuilt my own site, I replaced that whole chain with one n8n workflow. Every real enquiry now gets stored in a spreadsheet and pings my phone on Telegram within a few seconds. Bots get rejected before they cost me anything. Here is exactly how it is built, so you can copy the pattern.&lt;/p&gt;

&lt;h2&gt;
  
  
  The shape of the workflow
&lt;/h2&gt;

&lt;p&gt;The workflow has fourteen nodes, but the logic is simple:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Webhook&lt;/strong&gt;: receives the form POST from the website.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Normalize&lt;/strong&gt;: a Code node that trims and cleans the fields.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Honeypot check&lt;/strong&gt;: drops obvious bots quietly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validation&lt;/strong&gt;: rejects incomplete submissions with a clear error.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Turnstile verification&lt;/strong&gt;: asks Cloudflare whether the visitor is human.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Save to Google Sheets&lt;/strong&gt;: one row per lead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Telegram message&lt;/strong&gt;: an instant notification.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Respond&lt;/strong&gt;: tells the website whether it worked, so the visitor sees a thank-you page or an error.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each step does one job, and the order matters. The cheap checks come first and the external calls come last.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: a webhook that only does one thing
&lt;/h2&gt;

&lt;p&gt;The site is a static build on Cloudflare Pages, so there is no backend of its own. The form posts JSON straight to an n8n Webhook node set to "respond using a Respond to Webhook node". That setting is important. The browser waits for n8n to decide, which means you can return a real &lt;code&gt;200&lt;/code&gt;, &lt;code&gt;400&lt;/code&gt; or &lt;code&gt;403&lt;/code&gt; instead of always saying "thanks".&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: normalize before you check anything
&lt;/h2&gt;

&lt;p&gt;Forms send messy data: trailing spaces, uppercase emails, empty strings that should be missing. A short Code node fixes that once, so every later node can trust the shape of the data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="na"&gt;json&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;company&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;company&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;      &lt;span class="c1"&gt;// honeypot field&lt;/span&gt;
  &lt;span class="na"&gt;token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cf-turnstile-response&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;
&lt;span class="p"&gt;}}];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: the honeypot, the cheapest spam filter there is
&lt;/h2&gt;

&lt;p&gt;The form has a hidden field that real people never see. Bots that blindly fill every input fill it in too. If the honeypot is not empty, the workflow returns a normal &lt;code&gt;200&lt;/code&gt; and stops. The bot thinks it succeeded and moves on, and nothing reaches the sheet or my phone. It costs zero API calls.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: validate and fail loudly
&lt;/h2&gt;

&lt;p&gt;If the name, email or message is missing, or the email does not look like an email, the workflow responds with &lt;code&gt;400&lt;/code&gt;. The front end shows "please check the form" instead of pretending everything went fine. Silent failures are the main reason small businesses lose leads without ever knowing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Cloudflare Turnstile, verified on the server
&lt;/h2&gt;

&lt;p&gt;Turnstile is Cloudflare's free CAPTCHA alternative. Most visitors never click anything. The widget in the browser produces a token, but &lt;strong&gt;the token means nothing until your server checks it&lt;/strong&gt;. An HTTP Request node posts the token and the secret key to &lt;code&gt;https://challenges.cloudflare.com/turnstile/v0/siteverify&lt;/code&gt;. An IF node then reads &lt;code&gt;success&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Two practical tips:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep the secret in a Set ("Config") node or in n8n credentials, never in the front end.&lt;/li&gt;
&lt;li&gt;If the check fails, return &lt;code&gt;403&lt;/code&gt;. Real users almost never see it, but headless browsers and scripted tests often will. I learned that while testing my own form from an automated browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 6: store every lead somewhere boring and reliable
&lt;/h2&gt;

&lt;p&gt;A Google Sheets node appends a row with the timestamp, name, email, message and the page the visitor came from. A spreadsheet is not a CRM, but it is searchable, shareable and impossible to lose. Later you can add a node that pushes the same data into SuiteCRM, HubSpot or whatever you use, without touching the website.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Telegram, because email is where leads go to die
&lt;/h2&gt;

&lt;p&gt;The last action is a Telegram node that sends me a short message: who, what, and a link to the sheet. I see it on my phone within seconds, wherever I am. For a one-person business, replying in ten minutes instead of the next morning is the cheapest conversion boost there is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 8: tell the browser what happened
&lt;/h2&gt;

&lt;p&gt;Every branch ends in a Respond to Webhook node: &lt;code&gt;200&lt;/code&gt; for success (and for the honeypot), &lt;code&gt;400&lt;/code&gt; for invalid input, &lt;code&gt;403&lt;/code&gt; for a failed Turnstile check. The front end turns these into a thank-you redirect or a clear error message. You can also fire a &lt;code&gt;generate_lead&lt;/code&gt; event to Google Analytics only on a real &lt;code&gt;200&lt;/code&gt;, so your conversion numbers are honest.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it costs and what it saves
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cost:&lt;/strong&gt; Turnstile is free, Telegram is free, and Google Sheets is free. n8n runs self-hosted on a small server I already pay for.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Saves:&lt;/strong&gt; no spam in the inbox, no missed enquiries, and no paid form tool with a monthly fee per seat.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ownership:&lt;/strong&gt; the workflow, the data and the server are mine. If I change the website, the workflow stays the same.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Make it yours
&lt;/h2&gt;

&lt;p&gt;This pattern works for any static site: Astro, Next.js, Hugo or plain HTML. Start with the webhook, honeypot and Telegram nodes, which take about 30 minutes. Then add Turnstile and storage. Once leads arrive reliably, you can add AI steps, such as classifying the enquiry or drafting a first reply.&lt;/p&gt;

&lt;p&gt;I build workflows like this for small businesses in the Netherlands and across the EU. If you would rather not wire it up yourself, here is what an &lt;a href="https://alecasgari.com/services/n8n-automation" rel="noopener noreferrer"&gt;n8n automation project&lt;/a&gt; with me looks like, or see &lt;a href="https://alecasgari.com/projects" rel="noopener noreferrer"&gt;more of my work&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>n8n</category>
      <category>automation</category>
      <category>webdev</category>
      <category>smallbusiness</category>
    </item>
  </channel>
</rss>
