twilio receive sms with cURL

127 views Asked by At

I am a new user to twilio, and as I enter the panel, i see ads about "sends sms" and rarely or almost never about receive sms...

Even when i google something similar to twilio receive sms curl i get links on how to send sms and this is weird, as twilio keeps that to front way too much.

I was reading this blog and through the end of the page, if you look, it shows an example on how to send an sms using cURL and no example on how to receive sms on a number.

This is the example cURL post request from the blog link,

curl -X POST -d "Body=Hi there, this is a test message from cURL" -d "From=%TWILIO_NUMBER%" -d "To=%TO_NUMBER%" "https://api.twilio.com/2010-04-01/Accounts/%TWILIO_ACCOUNT_SID%/Messages" -u "%TWILIO_ACCOUNT_SID%:%TWILIO_AUTH_TOKEN%"

How do I check for inbound sms with such a similar curl request for a specific number using cURL ?

any help is appreciated, as this has been a rough research for some reason.

Edit: I found by researching myself that I can go to this link,

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

and it asks for authentication, then i can see all the messages i received.

how can i auth with a get request do i need to add queries such as

?TWILIO_ACCOUNT_SID=XXXX&TWILIO_AUTH_TOKEN=XXXXX

and how can I look for a specific number's incoming messages because this above link showing all the ones received in xml format.

maybe something like

?to=XXXXX

or

?number=XXXXX

to summarize, changing this to

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

something like this, will it work (again for inbound messages)

https://api.twilio.com/2010-04-01/Accounts/AccountSIDHERE/Messages?TWILIO_ACCOUNT_SID=XXXX&TWILIO_AUTH_TOKEN=XXXXX&number=XXXXX
1

There are 1 answers

0
Alan On

Try adding .json to the end of messages or .csv for alternate formats.

To see messages in real time, you need a service listening on your machine, that twilio can send a webhook to.

For a quick way to see this download Ngrok and bring it up and put the temporary https URL it proves you (which changes each time you run Ngrok) in as the SMS destination for incoming where you setup your number in the twilio console.

Then visit http://127.0.0.1:4040, the Ngrok debug port, to see the incoming webhooks.