Learning path: An AI agent on WhatsApp with n8nStep 4 of 5

WhatsApp· 5 min read

WhatsApp error 131047: the 24-hour window and templates


Error 131047 means you sent a free-form message through Meta’s WhatsApp Cloud API to a customer whose last message to you is more than 24 hours old. Meta’s error reference gives the detail text as “More than 24 hours have passed since the recipient last replied to the sender number” (Meta error codes reference). Its one suggested fix is “Send the recipient a template message instead.” The message was not delivered. Send an approved template, or wait for the customer to write again and reply inside the window.

131047 WhatsApp Cloud API (Meta)

Meaning
More than 24 hours have passed since the customer last wrote to you. The message was not delivered.
Fix
Send an approved template, or wait for the customer to write again and reply inside the window.

What the customer service window is

Meta’s send messages guide defines it in one sentence: “When a WhatsApp user messages you or calls you, a 24-hour timer called a customer service window starts.” Two more sentences on the same page settle the rest (Meta send messages guide). “If the user messages or calls you again before the timer expires, the timer resets to 24 hours.” “When the window closes, you can only send pre-approved template messages.”

The timer counts from the customer’s last message or call. Your replies do not extend it. A customer who wrote at 09:00 on Monday and received six answers from you can still only be messaged free-form until 09:00 on Tuesday, unless they write again.

The 24-hour customer service windowA customer writes on Monday at 09:00, which opens a 24-hour window. You reply several times; the window still closes on Tuesday at 09:00. After that, only template messages can be sent.Free-form messages allowedTemplates onlyMon 09:00Tue 09:00Customer writesYour replies (do not extend it)Window closes
The window counts from the customer's last message. Your replies inside it do not move the end. After it closes, only an approved template goes through; a free-form message returns 131047.

Inside the window you send what Meta calls service messages. “Service messages are free-form messages that you can send to WhatsApp users during a customer service window” (same guide). “Unlike template messages, service messages do not require pre-approval.” Text, image, document, audio, video, location, sticker, reaction and interactive messages all qualify.

What 131047 looks like in your logs

Meta returns errors “either synchronously as a Graph API response, asynchronously via Webhook, or sometimes through both methods” (error codes reference). For 131047 that means two places to check. The response to your POST /<WHATSAPP_BUSINESS_PHONE_NUMBER_ID>/messages call can carry it in the error object Meta documents as:

{
  "error": {
    "message": "<MESSAGE>",
    "type": "<TYPE>",
    "code": <CODE>,
    "error_data": {
      "messaging_product": "whatsapp",
      "details": "<DETAILS>"
    },
    "error_subcode": <ERROR_SUBCODE>,
    "fbtrace_id": "<FBTRACE_ID>"
  }
}

For 131047, code is 131047 and details is the sentence quoted above. The second place is the status webhook. A message the API accepted can later arrive with "status": "failed" and an errors array whose entries carry code, title, message, error_data.details and href (Meta status webhook reference).

Free-form message or template

Service (free-form) message Template message
When you may send it Inside an open customer service window Any time, to a customer who has opted in
Approval None Status must be APPROVED
Category service marketing, utility or authentication
Who opened the exchange The customer You
Meta’s charge 1,000 delivered per business phone number per month free, then charged (Meta pricing page, accessed 2026-10-28) Charged per delivered message by category and market (Meta pricing page, accessed 2026-10-28)

“Template messages are the only type of message that can be sent to WhatsApp users outside of a customer service window”, and “Templates must have a status of APPROVED before they can be sent in template messages” (Meta templates overview). The send request sets "type": "template" and a template object with the template name and language.code; Meta’s example uses order_confirmation in en_US.

A template does not replace consent. “Businesses are required to obtain opt-in before messaging people on WhatsApp” (Meta opt-in requirements). A customer who never agreed to hear from you is out of reach after 24 hours whether or not you have an approved template.

The service message charge is new. Until 30 September 2026 every service message was free; since 1 October 2026 Meta charges after the monthly tier. Meta charges for WhatsApp service messages since October 2026 has the detail.

Know the window state before you send

None of the Meta pages above describes an endpoint that returns whether a window is open, so you keep that state yourself. The inbound message webhook carries a timestamp for each message a customer sends you (Meta messages webhook reference). Store the latest one per customer and compare before every free-form send.

-- on every inbound message webhook
UPDATE contacts
SET last_inbound_at = to_timestamp(INBOUND_TIMESTAMP)
WHERE wa_id = 'WA_ID';

-- before sending a free-form message
SELECT last_inbound_at > now() - interval '23 hours' AS window_open
FROM contacts
WHERE wa_id = 'WA_ID';

The 23-hour margin covers clock drift and queue delay. If window_open is false, send the template straight away instead of trying the free-form message first. If you still get 131047 on a free-form send, treat it as the truth. Mark the window closed for that customer, send the template, and do not retry the free-form message. Retrying produces the same error.

Do not read the window from status webhooks. The conversation.expiration_timestamp field is “only included for sent status” (Meta status webhook reference). From Graph API v24.0 the conversation object “will be omitted entirely” except for messages inside a free entry point window. Code that depended on it stops seeing the field after an API version upgrade.

Only the official API has this error

The customer service window, template approval and 131047 are rules of Meta’s WhatsApp Business Platform. A QR connection drives a WhatsApp Web session under a phone number, so there is no window to track, no template to approve and no 131047 to handle. It has its own failure modes, and QR connection vs Meta’s official API lays both sets out on the same axes.

If you run both, keep the window logic on the official side only. Z-API Omni offers the two connections in the same account, and on the official connection Meta’s fees are passed through as Meta bills them (View documentation).

Z-API Omni team