Home > OS >  How to send the components in whatsapp cloud api?
How to send the components in whatsapp cloud api?

Time:05-30

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

CodePudding user response:

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

CodePudding user response:

Can I see the body and header of your template?

  • Related