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

Meta WhatsApp位置请求消息Body配置错误致400报错求助

修正位置请求消息的请求Body及调用代码

问题分析与修正点

你的请求返回400错误,核心问题出在以下3个地方:

  • interactive.body字段冗余了type: "text",Meta的位置请求消息规范中,body仅需text字段即可
  • to字段必须是不带+号的完整WhatsApp ID(包含国家码的纯数字,比如12345678901),不能使用带格式的手机号
  • Axios的POST请求参数格式错误,headers需要包裹在config对象中传递

修正后的请求Body

const body = {
  recipient_type: "individual",
  to: "12345678901", // 替换为目标用户的纯数字WhatsApp ID(无+号)
  type: "interactive",
  interactive: {
    type: "location_request_message",
    body: {
      text: "请分享你的位置" // 仅保留text字段,移除多余的type
    },
    action: {
      name: "send_location"
    }
  }
};

修正后的Axios请求代码

return new Promise((next) => {
  const headers = {
    "Content-Type": "application/json",
    Authorization: `Bearer ${token}`
  };

  AxiosService.post(
    `https://graph.facebook.com/${VERSION}/${JC_PHONE_ID}/messages`,
    body,
    { headers } // 这里要把headers放在config对象中,而非直接传递
  )
  .then((response) => {
    console.log(response.status);
    next({ success: response.status === 200, status: response.status });
  })
  .catch((err) => {
    // 建议打印错误详情,方便排查后续问题
    console.error("API请求错误:", err.response?.data || err.message);
    next({ success: false, status: err.response?.status || 400 });
  });
});

额外排查建议

如果修正后仍报错,建议:

  • 检查JC_PHONE_ID和VERSION是否为有效值(VERSION应为v18.0这类当前支持的版本号)
  • 查看err.response.data中的错误详情,Meta的Graph API会返回具体的错误原因(比如字段缺失、权限不足等)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 09:32:51