You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用WhatsApp Cloud API发送模板消息报错:Unexpected key "0" on param "template"

解决WhatsApp Cloud API模板消息报错:Unexpected key "0" on param "template". [type]

错误原因

你的请求中template.components的结构不符合API要求。当前写法把header和body分别放在两个独立的数组里,导致components变成了包含两个子数组的二维数组,而WhatsApp API要求components是直接包含各个组件对象的一维数组。

修正后的代码

"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),
            )
        )
    )
)

关键修改点

  • 移除了components下header和body外层多余的数组包裹,让两个组件直接成为components数组的元素。
  • 确保components是一维数组,每个元素对应一个模板组件(header、body、button等)。

内容的提问来源于stack exchange,提问作者crazyboy24

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 02:35:16