WhatsApp Cloud Api - Header & Body Template Message Php

Viewed 28

I am trying to send a WhatsApp template message using Whatsapp Cloud API.

I am getting an error:

Unexpected key "0" on param "template". [type]

This is the Request that I am sending via Curl Post:

    "messaging_product"=> "whatsapp",
    "recipient_type" => "individual",
    "to" => "$to_number",
    "type" => "template",
    'template' => array("name"=> "templateName",'language'=>array("code"=>"en"),
    'components'=>
        array(
            array(
                "type" => "header",
                "parameters" => array(
                    array(
                        "type" => "image",
                        "image" => array(
                            "link" => $imageLink
                        )
                    )
                )
            )
        ),
        array(
            array(
                "type" => "body",
                "parameters" => array(
                    array("type"=> "text","text"=> $Productid),
                )
            )
        )
   )
2 Answers

It looks like you have passed the wrong property array (that contains the body type) in components property,

It should be,

array(
    'messaging_product' => "whatsapp",
    'recipient_type' => "individual",
    'to' => "$to_number",
    'type' => "template",
    'template' => array(
        'name' => "templateName",
        'language' => array( 
           'code' => "en"
        ),
        'components' => array(
            array(
                'type' => "header",
                'parameters' => array(
                    array(
                        'type' => "image",
                        'image' => array(
                            'link' => $imageLink
                        )
                    )
                )
            ),
            array(
                'type' => "body",
                'parameters' => array(
                    array(
                        'type' => "text",
                        'text' => $Productid
                    )
                )
            )
        )
    )
)

What kind of template should you create to work with this code?

Related