0

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?

1 Answer 1

0

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
                    }
                }
            ]
        }
    ]
}

}

3
  • Thanks for help, I did it like you you told me but it still giving me the same error. Commented Jun 29 at 15:33
  • Could you add the json, which works without error, when u send without variable ?
    – Partha
    Commented Jun 30 at 16:44
  • nvm you are right it was another problem, thank you for helping. Commented Jul 4 at 22:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.