Search code examples
node.jsaxioswhatsappwhatsapp-cloud-apiwhatsapp-flows

Error 404 when sending WhatsApp template message with variable in Node.js


I'm trying to send a WhatsApp template message using the flow API as described in this guide. The template sends correctly when there's no variable in the body, but fails with a 404 error when I include a variable. Here's quote of my Node.js code:


let from = req.body.entry[0].changes[0].value.messages[0].from;

let flowtest= {
    messaging_product: "whatsapp",
    recipient_type: "individual",
    to: from,
    type: "template",
    template: {
        name: "flowtest",
        language: {
            code: "ar",
        },
        components: [
            {
                type: "body",
                parameters: [
                    {
                        type: "text",
                        text: from,
                    },
                ],
                type: "button",
                sub_type: "flow",
                index: "0",
            },
        ],
    },
};

I followed the official documentation and constructed the message payload as shown above. The request works without any errors when the message body does not contain any variables. However, adding a variable to the body component of the template (as shown in the code) causes the request to fail.

I expected the message to be sent successfully with the variable (from in this case) being included in the message body as specified.

When I try to send the message with the variable included in the body, I receive the following error:

Error sending message: Request failed with status code 404

Can anyone help me understand why this error occurs and how to fix it?


Solution

  • Variables for flow and template body are given separately. Try something like this

    {
    "messaging_product": "whatsapp",
    "recipient_type": "individual",
    "to": from,
    "type": "template",
    "template": {
        "name": "flowtest",
        "language": {
            "code": "ar"
        },
        "components": [
            {
                "type": "body",
                "parameters": [
                    {
                        "type": "text",
                        "text": from
                    }
                ]
            },
            {
                "type": "button",
                "sub_type": "flow",
                "index": "0",
                "parameters": [
                    {
                        "type": "action",
                        "action": {
                            "flow_token": "FLOW_TOKEN",
                            "flow_action_data": initialData
                        }
                    }
                ]
            }
        ]
    }
    

    }