6

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.

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that's what I was afraid of. I'll have to override my software's build-in web service icon with straight java code since for some reason they implemented it with the expectation that the payload would always be XML or JSON. Thanks for your answer. After a day of testing with no success I can move on.
-1

Your HTTP request needs to be a "form" request, not "json".

I agree that it's not perfectly documented, but it fixed the error for me after I learned that.

1 Comment

Isn't it what @philnash already explained in their answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.