Twilio gives error 400

Hi all,

I have a twilio integration, that worked fine for the past few years, and is no longer working.
It authenticates, but the “To”: number does not go thru.

Can anyone help? Thx, J

Integration JSON Data:

{
“name”: “TankWatchTwilio”,
“data”: “{“n”:”+1234567890", “m”:“TANK WATCH - LOW LEVEL ALERT!!! Tank is 44 percent full.”}",
“ttl”: 60,
“published_at”: “2021-07-15T15:00:08.911Z”,
“coreid”: “mycoreid”,
“userid”: “myuserid”,
“version”: 44,
“public”: false,
“productID”: 5031
}

The Request Sent:

POST /2010-04-01/Accounts/myuserid/Messages?Body=TANK%20WATCH%20-%20LOW%20LEVEL%20ALERT%21%21%21%20HTank%20is%2044%20percent%20full.&To=%2B1234567890&From=%2B1%20234%20567%20890 HTTP/1.1
User-Agent: ParticleBot/1.1 (https://docs.particle.io/webhooks)
host: api.twilio.com
content-type: application/x-www-form-urlencoded
authorization: Basic QUNjYmRmMTU5MDBlODBjZmZkMjhhM2RlYjg1MjhmYTU1YzplNjE0YTM0NDZkZWUxMjk4YmZiYjAyYWIxZTE2M2Q5ZA==
content-length: 317
Connection: keep-alive

The response:

HTTP/1.1 400 Bad Request
Date: Thu, 15 Jul 2021 15:01:09 GMT
Content-Type: application/xml
Content-Length: 253
Connection: keep-alive
Twilio-Request-Id: myuserid
Twilio-Request-Duration: 0.037
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since
Access-Control-Allow-Methods: GET, POST, DELETE, OPTIONS
Access-Control-Expose-Headers: ETag
Access-Control-Allow-Credentials: true
X-Powered-By: AT-5000
X-Shenanigans: none
X-Home-Region: us1
X-API-Domain: api.twilio.com
Strict-Transport-Security: max-age=31536000

<?xml version='1.0' encoding='UTF-8'?>

21604A ‘To’ phone number is required.Error 21604 - Twilio400

I use a Twilio webhook to send SMS and mine is still working. However, there is an important difference between mine and yours.

In yours, you have all of the message parameters in the URL, which isn’t the way POST requests are usually made. Some web servers treat URL parameters the same as post body parameters, but some do not. There could have been a change in the Twilio backend that affects this, for example, but I do not know if that’s the case.

In any case, the recommended way to use it is to have the URL end with Messages.json.

Set the request type to POST, which you do have already.

Set the Request Format to Web Form. This is different than what you have set, I think.

Set the form fields appropriately. I set the To and Body from the event data, but you can hardcode those as needed if you prefer.

The authorization should be the same.

OK, I have made some changes, fingers crossed. I did have a bunch of extra stuff in the FORM, and the to, from, and body were in query parameters. I was using the Web Form Request Format.
Thanks for the help

1 Like