Search code examples
laravelwhatsappwhatsapi

WhatsApp Business API send media template error


I have created a media template in what's app business API. But I cannot send the template message where the media file is attached in the header.

My media template object.

{
    "name": "business_five",
    "components": [
        {
            "type": "HEADER",
            "format": "IMAGE",
            "example": {
                "header_handle": [
                    "https://scontent.whatsapp.net/v/t61.29466-34/323170987_1239753446972881_6537482729362490175_n.jpg?ccb=1-7&_nc_sid=57045b&_nc_ohc=24dzgQb3Xc8AX9Nllk_&_nc_ht=scontent.whatsapp.net&edm=AH51TzQEAAAA&oh=01_AdRx0hLfUqy4nKvgGz1cf23Em9ElezWo1o4UPrfwPGeVgg&oe=64336E79"
                ]
            }
        },
        {
            "type": "BODY",
            "text": "Dear All,\nWishing you ramadan mubarak."
        }
    ],
    "language": "en_US",
    "status": "APPROVED",
    "category": "MARKETING",
    "id": "1235769690704590"
}

When I'm sending this template message to others using the API https://graph.facebook.com/{{version}}/{{phone_number_id}}/messages
it's showing the error :

(#132012) Parameter format does not match format in the created template

Can anyone help me with how can I send a media template message? My post field was

$message = [
    "messaging_product" => "whatsapp",
    "to" => "8801704158504",
    "type" => "template",
    "template" => [
        "name" => $template->name,
        "language" => [
            "code" => $template->language
        ],
        "components" => [
            [
                "type" => "header",
                "parameters" => [
                    'type' => 'image',
                    'image' => [
                        'link' => 'https://imgur.com/a/wu3BP6R'
                    ]
                ]
            ]
        ]
    ]
];

Solution

    • You are missing the bracket after parameters property,
    • Second, there is an issue with the media URL also, you need to pass the exact destination of the image instead of the routing path like it should have an extension .jpeg/.png
    "parameters" => [
      [
        'type' => 'image',
        'image' => [
          'link' => 'https://imagepath/image-name.jpeg' // or .png
        ]
      ]
    ]