I want to send the parameters in in whatsapp cloud api. How can I achieve that.
$messageData = array(
'messaging_product' => "whatsapp",
'to' => "123456789",
'type' => "template",
'template' => array("name"=> "hello_world",'language'=>array("code"=>"en_Us")),
);
I want it like this
{
type: 'template',
messaging_product: 'whatsapp',
to: e.recipient_number,
template: {
name: WHATSAPP_TEMPLATE_NAME,
language: { code: LANGUAGE_CODE },
components: [
{
type: 'body',
parameters: [
{ type: 'text', text: e.customer_name },
{ type: 'text', text: e.item_name },
{ type: 'text', text: e.delivery_date },
],
},
],
},
}
The error I am getting
{"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 (3)"},"error_subcode":2494073,"fbtrace_id":"Abab9mTp_dJ9Ryd4ytHPl7Y"}}
First of all, the hello_world template is a pre-defined template, created by the Whatsapp business API team. If you need to send parameters, you have to create a template with variables in its body like
URL - {{1}}
Then pass parameter like this,
var data = JSON.stringify({
"messaging_product": "whatsapp",
"to": number,
"type": "template",
"template": {
"name": "template_name",
"language": {
"code": "language_code"
},
"components": [
{
"type": "body",
"parameters": [{
"type": "text",
"text":"https://www.whatsapp.com"
}]
}],
}});
Your output message will be URL - https://www.whatsapp.com
$messageData = array(
'messaging_product' => "whatsapp",
'to' => 123456789,
'type' => "template",
'template' => array("name"=> "random name",'language'=>array("code"=>"en_Us"),'components'=>
array(array(
"type" => "body",
"parameters" => array(array("type"=> "text","text"=> google.com),array("type"=> "text","text"=> $shopName),array("type"=> "text","text"=> 123456789)))))
);
From "Sarkar's Answer above,
{
"messaging_product": "whatsapp",
"to": 123456789,
"type": "template",
"template": {
"name": "random name",
"language": {
"code": "en_Us"
},
"components": [
{
"type": "body",
"parameters": [
{
"type": "text"
},
{
"type": "text"
},
{
"type": "text",
"text": 123456789
}
]
}
]
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.