How to send SMS via MessageBird API

191 Views Asked by At

I am currently follwing MEssageBird sms documentation here https://docs.messagebird.com/api/channels-api/supported-channels/programmable-sms/sending-messages

I am using restsharp and making an httppost request and I get an error from the API. Unprocessed Entity. {"code":"InvalidPayload","message":"One or more fields provided in the request body are malformed: no matching operation was found"}.

My JsonString is

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

My json object is almost identical to the documentation.

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);

May I ask if anyone has any suggestions on where I may be going wrong on sending an httppost to MessageBird.

1

There are 1 best solutions below

0
On

I recommend that you use this documentation to send messages: https://developers.messagebird.com/api/conversations/#send-message

Now to know how to send all types of messages if you use the documentation: https://docs.messagebird.com/api/channels-api/supported-channels/programmable-sms/sending-messages

payload = {
            "content": {
                "interactive": {
                    "type": "button",
                    "header": {
                        "type": "image",
                        "image": {
                            "url": "https://xxx"
                        }
                    },
                    "body": {
                        "text": preguntas
                    },
                    "action": {
                        "buttons": [
                            {
                                "id": "yes-unique-id",
                                "type": "reply",
                                "title": respuesta_1
                            },
                            {
                                "id": "no-unique-id",
                                "type": "reply",
                                "title": respuesta_2
                            }
                        ]
                    },
                    "footer": {
                        "text": "We have this one in other colors."
                    }
                }
            },
            "to": number,
            "type": "interactive",
            "from": canal
        }

        headers = {
            "Authorization": "AccessKey xxxxxxxxxxxxxx",
            "Content-Type": "application/json; charset=utf-8"
        }

        response = requests.post("https://conversations.messagebird.com/v1/send", json=payload, headers=headers)