2
votes

The platform I am using forces me to send POST requests with a body of JSON format or XML format, so to test I am using SOAPUI so I can specify exactly the body I need for testing. I am POSTing to the URL https://api.twilio.com/2010-04-01/Accounts/ACxxxxxxxxxxxxxxxxxxxx/Messages.json

with a JSON body of

{
    "Body": "hi dear",
    "To": "+1631xxxxxxx",
    "From": "82xxx"
}

but it generates the error

{"code": 21604, "message": "A 'To' phone number is required.", "more_info": "https://www.twilio.com/docs/errors/21604", "status": 400}

but if the SOAP body is simple parameters

To=%2B1631xxxxxxx&From=82xxx&Body=Hi%20Dear

The message is send correctly and I get the Twilio response of

{
    "sid": "SMxxxxxxxxxxxxxxxxxxxxx",
    "date_created": "Tue, 06 Oct 2020 03:00:01 +0000",
    "date_updated": "Tue, 06 Oct 2020 03:00:01 +0000",
...
}

Does Twilio have a messages API that I can POST with a formatted JSON or XML body.

1

1 Answers

2
votes

Twilio developer evangelist here.

The Twilio API only accepts requests with the body formatted as application/x-www-form-urlencoded or simple parameters as you mention in your post. That is the only way to make requests to the Twilio API.

The core APIs will respond with XML (by default) or optionally JSON, CSV and HTML by appending the relevant suffix (.json as you have included, .csv or .html). Newer APIs, anything under a subdomain like productname.twilio.com/v1, only respond with JSON.

Twilio also provides helper libraries in 6 different languages, and there are community maintained libraries for many unsupported languages, that should abstract away the format of the request.

Let me know if that helps at all.