Skip to content
This repository was archived by the owner on Feb 1, 2018. It is now read-only.

Latest commit

 

History

History
72 lines (47 loc) · 1.75 KB

File metadata and controls

72 lines (47 loc) · 1.75 KB

Quickstart

Getting started with the Twilio API couldn't be easier. Create a Twilio REST client to get started. For example, the following code makes a call using the Twilio REST API.

Make a Call

from twilio.rest import TwilioRestClient

# To find these visit https://www.twilio.com/user/account
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"

client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
call = client.calls.create(to="9991231234", from_="9991231234",
    url="http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
print call.length
print call.sid

Send an SMS

from twilio.rest import TwilioRestClient

account = "ACXXXXXXXXXXXXXXXXX"
token = "YYYYYYYYYYYYYYYYYY"
client = TwilioRestClient(account, token)

message = client.sms.messages.create(to="+12316851234",
                                     from_="+15555555555",
                                     body="Hello there!")

Generating TwiML

To control phone calls, your application needs to output TwiML. Use :class:`twilio.twiml.Response` to easily create such responses.

from twilio import twiml

r = twiml.Response()
r.play("https://api.twilio.com/cowbell.mp3", loop=5)
print str(r)
<?xml version="1.0" encoding="utf-8"?>
<Response>
    <Play loop="5">https://api.twilio.com/cowbell.mp3</Play>
<Response>

Digging Deeper

The full power of the Twilio API is at your fingertips. The :ref:`user-guide` explains all the awesome features available to use.