How to hit the Twilio API

Twilio's core API lives at https://api.twilio.com/2010-04-01, with every path under your Account SID. Request bodies are form-encoded; add .json to the path to get JSON back.

Authentication

Twilio uses Basic auth: your Account SID as the username and your Auth Token as the password, both on the Twilio Console home page. That's curl's -u; in PostTaco it lands in the Auth tab. In the examples they're written {{TWILIO_ACCOUNT_SID}} and {{TWILIO_AUTH_TOKEN}}.

Phone numbers are E.164 (+15558675310). In a form body a + means a space, so the examples write it as %2B — enter the number's digits without the plus.

Full reference: https://www.twilio.com/docs/usage/api

Send an SMS

From must be a Twilio number you own. Returns the message with its sid and status.

curl -X POST https://api.twilio.com/2010-04-01/Accounts/{{TWILIO_ACCOUNT_SID}}/Messages.json \
  -u {{TWILIO_ACCOUNT_SID}}:{{TWILIO_AUTH_TOKEN}} \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "To=%2B{{TO_NUMBER}}" \
  -d "From=%2B{{TWILIO_NUMBER}}" \
  -d "Body=Hello from PostTaco"
Run in PostTaco

List messages

Newest first. Filter with To, From, or DateSent.

curl "https://api.twilio.com/2010-04-01/Accounts/{{TWILIO_ACCOUNT_SID}}/Messages.json?PageSize=10" \
  -u {{TWILIO_ACCOUNT_SID}}:{{TWILIO_AUTH_TOKEN}}
Run in PostTaco

Make a phone call

Twilio fetches TwiML from Url to decide what to say — this one is Twilio's own demo, which reads a short message.

curl -X POST https://api.twilio.com/2010-04-01/Accounts/{{TWILIO_ACCOUNT_SID}}/Calls.json \
  -u {{TWILIO_ACCOUNT_SID}}:{{TWILIO_AUTH_TOKEN}} \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "To=%2B{{TO_NUMBER}}" \
  -d "From=%2B{{TWILIO_NUMBER}}" \
  -d "Url=http://demo.twilio.com/docs/voice.xml"
Run in PostTaco

Look up a phone number

Validates and formats a number. A + in a URL path is fine as-is. Extra data (carrier, line type) is opt-in via Fields.

curl https://lookups.twilio.com/v2/PhoneNumbers/+14155552671 \
  -u {{TWILIO_ACCOUNT_SID}}:{{TWILIO_AUTH_TOKEN}}
Run in PostTaco

Get your account

Name, status, and type — the quickest check that your SID and token are right.

curl https://api.twilio.com/2010-04-01/Accounts/{{TWILIO_ACCOUNT_SID}}.json \
  -u {{TWILIO_ACCOUNT_SID}}:{{TWILIO_AUTH_TOKEN}}
Run in PostTaco