Twilio Webhook Failure - Missing To phone number error

My Particle event is executing a Webhook to Twilio. But the call fails with a message that the ‘To’ phone number is missing. But it is sending in JSON format and the JSON block has a To, From, and Body.

The call works just fine if I execute it as a cURL call from a console. Not sure why it does not see the data in the JSON block POSTed.

Webhook Configuration:

Webhook Response:

Can you also provide a log of the outgoing request?

Does the Twilio SMS API take a request in JSON format? The example in the Twilio API docs uses URL encoded POST format, as does this community post which uses web form encoding (application/x-www-form-urlencoded).

Using curl with the -d option also defaults to application/x-www-form-urlencoded.

How can I log the outbound Webhook?

This cURL command works properly. It is sending as Message.json…

curl –k/ --insecure –X POST https://api.twilio.com/2010-04-01/Accounts/AC08...415/Messages.json --data-urlencode “Body=This is from Twilio” --data-urlencode “From=+156…25” --data-urlencode “To=+156…800” -u "AC089…afa6

This setting is different than what you are sending in your curl command. Change this from JSON to Web Form.

I believe this is what you asked to see. But it only includes the headers and not the body of the request.

POST /2010-04-01/Accounts/AC089…15/Messages.json HTTP/1.1
User-Agent: ParticleBot/1.1 (https://docs.particle.io/webhooks)
host: api.twilio.com
authorization: Basic QUMwODljNWVlMTRjZWNmYTAzNmI3Yj…VlOGE3NTM2ODg0NGZhMWU3YWZhNg==
accept: application/json
content-type: application/json
content-length: 118
Connection: keep-alive

I think Rick is pointing out the actual cause for your issue, but in order to get the raw request you could temporarily redirect your webhook to a service like requestbin.com and see what they get and compare that against your expectations.

Working now. It was actually a combination of things. First, the URL is:

https://api.twilio.com/2010-04-01/Accounts/AC08...415/Messages

And yes, the body must be a Web Form as the Message.json option will not work with a JSON formed Particle Webhook. So the Webhook is sent as:

{
  Content-Type: "application/x-www-form-urlencoded"
}

BTW - Multiple webhooks may be initiated for the same event trigger. So in my case, I am texting multiple smartphones when my Particle device senses an event.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.