<?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: GetSetSales</title>
    <description>The latest articles on DEV Community by GetSetSales (@getsetsales).</description>
    <link>https://dev.to/getsetsales</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%2F4267783%2F391af5e0-b4f6-4978-9391-b3186142eb1e.png</url>
      <title>DEV Community: GetSetSales</title>
      <link>https://dev.to/getsetsales</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/getsetsales"/>
    <language>en</language>
    <item>
      <title>Sending a WhatsApp template from Node.js, and the 6 mistakes that make the API say no</title>
      <dc:creator>GetSetSales</dc:creator>
      <pubDate>Fri, 27 Nov 2026 15:08:45 +0000</pubDate>
      <link>https://dev.to/getsetsales/sending-a-whatsapp-template-from-nodejs-and-the-6-mistakes-that-make-the-api-say-no-2mij</link>
      <guid>https://dev.to/getsetsales/sending-a-whatsapp-template-from-nodejs-and-the-6-mistakes-that-make-the-api-say-no-2mij</guid>
      <description>&lt;p&gt;I work on GetSetSales, a WhatsApp Business API provider in India, so the examples use our public API. The mistakes are the same on most WhatsApp APIs, because they come from Meta's rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  The call
&lt;/h2&gt;

&lt;p&gt;Sending a WhatsApp message from your own code (an order confirmation, an OTP, a reminder) means sending a &lt;strong&gt;template&lt;/strong&gt;: a message Meta approved in advance. Free-form text only works inside the 24 hours after the customer last messaged you.&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="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"https://api.getsetsales.in/public/v1/messages"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"POST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`Bearer ${process.env.GSS_API_KEY}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"Idempotency-Key"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`order-${order.id}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"919999999999"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;templateName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"order_confirmation"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;languageCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"en"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customerName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sb"&gt;`#${order.id}`&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${res.status}: ${await res.text()}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;messageId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// "wamid.HBgM..."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;parameters&lt;/code&gt; fills &lt;code&gt;{{1}}&lt;/code&gt;, &lt;code&gt;{{2}}&lt;/code&gt; and so on, in order. If the template says "Hi {{1}}, your order {{2}} is confirmed", the customer reads "Hi Raksha, your order #1234 is confirmed".&lt;/p&gt;

&lt;h2&gt;
  
  
  Mistake 1: the phone number format
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;to&lt;/code&gt; is digits only, with the country code: &lt;code&gt;919999999999&lt;/code&gt;. Not &lt;code&gt;+91 99999 99999&lt;/code&gt;, not &lt;code&gt;09999999999&lt;/code&gt;. Strip spaces, dashes and the plus before you send, and add &lt;code&gt;91&lt;/code&gt; to Indian ten-digit numbers.&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="n"&gt;toWhatsApp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="no"&gt;D&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/^&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;+/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="sb"&gt;`91${d}`&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Mistake 2: a template that is not approved yet, or a different name
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;templateName&lt;/code&gt; must match an approved template on the sending number exactly. A template still "In review", or one approved under &lt;code&gt;order_confirmation_v2&lt;/code&gt; while your code says &lt;code&gt;order_confirmation&lt;/code&gt;, is refused. Keep template names in config, not scattered through the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mistake 3: the wrong language code
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;languageCode&lt;/code&gt; must match the language the template was approved in. A template approved as &lt;code&gt;en_US&lt;/code&gt; is not the same as &lt;code&gt;en&lt;/code&gt;, and a Hindi template is &lt;code&gt;hi&lt;/code&gt;. If you approved one template in two languages, they are two separate sends.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mistake 4: a template with an image header and no image
&lt;/h2&gt;

&lt;p&gt;If the template was approved with an IMAGE header, Meta rejects the send unless you pass one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"headerImageUrl"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://cdn.yoursite.com/banner.jpg"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It must be a public https link to a JPG or PNG. Meta fetches it itself, so a link behind a login or a signed URL that expires in a minute will fail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mistake 5: retrying and sending twice
&lt;/h2&gt;

&lt;p&gt;Network calls time out. If you retry blindly, the customer gets the OTP twice. Send an &lt;code&gt;Idempotency-Key&lt;/code&gt; header (an order ID works well). Retrying with the same key returns the first response again with &lt;code&gt;Idempotent-Replayed: true&lt;/code&gt;, and nothing is re-sent. Reusing the key for a different message body returns &lt;code&gt;422&lt;/code&gt;. Keys last 24 hours.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mistake 6: looping over 5,000 numbers
&lt;/h2&gt;

&lt;p&gt;Each account can make 20 requests a second. Past that you get &lt;code&gt;429&lt;/code&gt; with a &lt;code&gt;Retry-After&lt;/code&gt; header. More importantly, a loop of single sends is the wrong tool for a broadcast: schedule a campaign instead (&lt;code&gt;POST /public/v1/campaigns&lt;/code&gt;), which is paced for you and checks up front that the wallet can cover the whole send.&lt;/p&gt;

&lt;h2&gt;
  
  
  The status codes, in one place
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Code&lt;/th&gt;
&lt;th&gt;Usually means&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;400&lt;/td&gt;
&lt;td&gt;A required field is missing or wrong, or no connected number matches &lt;code&gt;phoneNumberId&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;402&lt;/td&gt;
&lt;td&gt;The wallet is below the ₹100 minimum&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;403&lt;/td&gt;
&lt;td&gt;The account is not approved yet, or the feature is not switched on&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;409&lt;/td&gt;
&lt;td&gt;Same idempotency key while the first call is still running&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;422&lt;/td&gt;
&lt;td&gt;Same idempotency key, different message&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;429&lt;/td&gt;
&lt;td&gt;Over 20 requests a second; wait &lt;code&gt;Retry-After&lt;/code&gt; seconds&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Before you write the template
&lt;/h2&gt;

&lt;p&gt;Most rejections happen before any code runs, at Meta's template review. Two rules catch most people: do not start or end the template with a variable (put a word before &lt;code&gt;{{1}}&lt;/code&gt; and after the last one), and do not put an offer inside a "utility" template, because Meta will call it marketing. There is a free checker for this at &lt;a href="https://getsetsales.in/whatsapp-template-checker" rel="noopener noreferrer"&gt;https://getsetsales.in/whatsapp-template-checker&lt;/a&gt;, no account needed.&lt;/p&gt;

&lt;p&gt;Full API reference: &lt;a href="https://docs.getsetsales.in" rel="noopener noreferrer"&gt;https://docs.getsetsales.in&lt;/a&gt;&lt;/p&gt;

</description>
      <category>whatsapp</category>
      <category>api</category>
      <category>node</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
