5

I created below template in Whatsapp API. And I want to set the parameter value in the API call. What is the correct payload ? I have been following the Meta docs and trying but everytime I get error. Please Help.

Template:

You order # {{1}} is received successfully.

enter image description here

I used this payload:

{
"messaging_product": "whatsapp", 
"to": "918456712349", 
"type": "template", 
"template": { 
    "name": "order_notification",
    "language": { 
        "code": "en_US" 
    }
},
"components": [
    {
        "type": "body",
        "parameters": [
            {
                "type": "text",
                "text": "135345345"
            }
        ]
    }
]
}

But I am still getting this error

{
"error": {
    "message": "(#132000) Number of parameters does not match the expected number of params",
    "type": "OAuthException",
    "code": 132000,
    "error_data": {
        "messaging_product": "whatsapp",
        "details": "body: number of localizable_params (0) does not match the expected number of params (1)"
    },
    "error_subcode": 2494002,
    "fbtrace_id": "AzPa-uWXctIcdNVu0Lf3Fic"
}

}

4 Answers4

18

The issue due to closing the template object then opening a new component object. make the component object inside the template object and it will be fixed

{
"messaging_product": "whatsapp", 
"to": "918456712349", 
"type": "template", 
"template": { 
    "name": "order_notification",
    "language": { 
        "code": "en_US" 
    }

"components": [
    {
        "type": "body",
        "parameters": [
            {
                "type": "text",
                "text": "135345345"
            }
        ]
    }
]
}
}
Hisham A
  • 181
  • 4
  • yes your answer is correct. In case of One time passwords, is the code (otp) itself is generated by us or by WhatsApp/Meta? – yunas Jul 07 '22 at 23:23
1

change in parameter type "header", this code run for me:

 {
    "messaging_product": "whatsapp", 
    "to": "918456712349", 
    "type": "template", 
    "template": { 
        "name": "order_notification",
        "language": { 
            "code": "en_US" 
        },
    "components": [
        {
            "type": "header",
            "parameters": [
                {
                    "type": "text",
                    "text": "xxxxxxx"
                }
            ]
        }
      ]
    }
 }
mufazmi
  • 1,103
  • 4
  • 18
  • 37
0

I got same issue, I changed my parameter structure as below:

            $parameters = [
                "messaging_product" => "whatsapp",
                "recipient_type" => "individual",
                "to" => $phone,
                "type" => "template",
                "template" => [
                    "name" => "otp_code",
                    "language" => ["code" => "en"],
                    "components" => [
                        [
                            "type" => "body",
                            "parameters" => [
                                ["type" => "text", "text" => $message],
                            ],
                        ],
                    ],
                ],
            ];
Akam
  • 1,089
  • 16
  • 24
-3

Looks like the template is expecting 1 parameter, which is not being provided.

You can look at the documentation and example here.

It includes a working example.

Languré
  • 14
  • 3
  • I am using Whatsapp Meta (Facebook) API. Not the Twilio API. – Kaushik Kumar Roy May 20 '22 at 17:04
  • I have prepared the payload as per this docs. https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-message-templates If I use a template that does not have any variables than there is no issue. Only for the case where I am using any variable in a template, than I get this error. I am not sure what is the correct payload for this scenario. – Kaushik Kumar Roy May 20 '22 at 17:10