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

使用MessageBird API发送SMS遇InvalidPayload错误,求排查建议

MessageBird SMS API 请求报错排查

问题描述

我在对接MessageBird的SMS API时,使用RestSharp发送POST请求,收到了如下错误返回:

Unprocessed Entity. {"code":"InvalidPayload","message":"One or more fields provided in the request body are malformed: no matching operation was found"}

我的请求JSON内容如下:

{
  "receiver": {
    "contacts": [
      {
        "identifierValue": "+1XXXXXXXXXX"
      }
    ]
  },
  "body": {
    "type": "text",
    "text": {
      "text": "Single Text Message"
    }
  }
}

对应的RestSharp代码:

var client = new RestClient("https://nest.messagebird.com/workspaces/XXXXXXX/channels/XXXXXXXX/messages");
var request = new RestRequest("Resources", Method.Post);
const string ApplicationJsonContentType = "application/json"; 
request.RequestFormat = RestSharp.DataFormat.Json;
request.AddHeader("Authorization", "AccessKey XXXXXXXXXXXXX");
request.AddBody(jsonString);
var response = client.Execute(request);

我对比过官方文档,JSON结构几乎一致,请问问题出在哪里?

排查与解决建议

  • 请求URL路径错误:你创建RestRequest时额外添加了"Resources"后缀,导致最终请求URL变成https://nest.messagebird.com/workspaces/XXXXXXX/channels/XXXXXXXX/messages/Resources,但发送短信的接口路径应该直接指向/messages。把new RestRequest("Resources", Method.Post)修改为new RestRequest(Method.Post)即可修正路径。
  • JSON提交方式错误:你设置了RequestFormat = DataFormat.Json,却用AddBody(jsonString)传递字符串格式的JSON。RestSharp会把字符串当成普通对象序列化,导致请求体被额外转义(比如外层多了引号),API无法正确解析。解决方法二选一:
    1. 定义对应C#实体类,实例化后传入AddBody,让RestSharp自动序列化;
    2. 改用request.AddStringBody(jsonString, DataFormat.Json)直接传递JSON字符串,确保Content-Type正确。
  • 字段名核对:再仔细检查JSON字段名,比如identifierValue是否符合当前API版本的要求,部分文档版本里接收方的号码字段可能是phoneNumber或msisdn,确认官方文档的最新定义。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 00:42:11