Reputation: 173
I know you can use HTTP POST passing in 'from', 'to' and 'body' as http parameters. But how can you send 'account sid' and 'auth token'? Can you use a request header or something? I would like to post without using PHP or Curl or any other libraries.
Thanks
Upvotes: 2
Views: 3790
Reputation: 10366
Twilio evangelist here.
As you mention to make a raw request to the Twilio REST API without a helper library you need to craft your own HTTP request. The specific HTTP Method you use for the request (GET,POST,PUT,DELETE) depends on what you want the API to do.
Twilio uses simple Basic authorization to authorize users of the API. To use Basic Authentication with HTTP you need to include in your HTTP request the Authorization
header and pass as its value the authorization scheme (in Twilio case this is "Basic") and a Base64 encoded string containing your accountsid and authtoken seperated by a semi-colon:
[AccountSid]:[AuthToken]
The HTTP header would end up looking something like this:
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
For example of you wanted to have Twilio send a text message you would craft an HTTP request using the POST method that looks like this:
POST https://api.twilio.com/2010-04-01/Accounts/[YOUR_ACCOUNT_SID]/Messages HTTP/1.1
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Host: api.twilio.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 50
To=+15555555555&From=+16666666666&Body=Hello World
Hope that helps.
Upvotes: 4