twilio.rest.resources

class twilio.rest.resources.ListResource(*args, **kwargs)
get(sid)

Get an instance resource by its sid

Usage:

message = client.messages.get("SM1234")
print message.body
Return type:InstanceResource
Raises:a TwilioRestException if a resource with that sid does not exist, or the request fails
iter(**kwargs)

Return all instance resources using an iterator

This will fetch a page of resources from the API and yield them in turn. When the page is exhausted, this will make a request to the API to retrieve the next page. Hence you may notice a pattern - the library will loop through 50 objects very quickly, but there will be a delay retrieving the 51st as the library must make another request to the API for resources.

Example usage:

for message in client.messages:
    print message.sid
class twilio.rest.resources.InstanceResource(parent, sid)

The object representation of an instance response from the Twilio API

Parameters:
  • parent (ListResource) – The parent list class for this instance resource. For example, the parent for a Call would be a Calls object.
  • sid (str) – The 34-character unique identifier for this instance

Accounts

class twilio.rest.resources.Accounts(*args, **kwargs)

A list of Account resources

activate(sid)

Reactivate an account, Alias to update

close(sid)

Permenently deactivate an account, Alias to update

create(**kwargs)

Returns a newly created sub account resource.

Parameters:friendly_name – Update the description of this account.
list(**kwargs)

Returns a page of Account resources as a list. For paging informtion see ListResource

Parameters:
  • friendly_name (date) – Only list accounts with this friendly name
  • status (date) – Only list accounts with this status
suspend(sid)

Temporarily suspend an account, Alias to update

update(sid, **kwargs)
Parameters:
  • sid – Account identifier
  • friendly_name – Update the description of this account.
  • status – Alter the status of this account

Use CLOSED to irreversibly close this account, SUSPENDED to temporarily suspend it, or ACTIVE to reactivate it.

class twilio.rest.resources.Account(parent, sid)

An Account resource

sid

A 34 character string that uniquely identifies this account.

date_created

The date that this account was created, in GMT in RFC 2822 format

date_updated

The date that this account was last updated, in GMT in RFC 2822 format.

friendly_name

A human readable description of this account, up to 64 characters long. By default the FriendlyName is your email address.

status

The status of this account. Usually active, but can be suspended if you’ve been bad, or closed if you’ve been horrible.

auth_token

The authorization token for this account. This token should be kept a secret, so no sharing.

ACTIVE = 'active'

A constant representing an active account

CLOSED = 'closed'

A constant representing a closed account

SUSPENDED = 'suspended'

A constant representing a suspended account

activate()

Reactivate this account

close()

Permenently deactivate this account

suspend()

Temporarily suspend this account

update(**kwargs)

Update the status of an account.

Parameters:
  • friendly_name – Update the description of this account.
  • status – Alter the status of this account

Use CLOSED to irreversibly close this account, SUSPENDED to temporarily suspend it, or ACTIVE to reactivate it.

Addresses

class twilio.rest.resources.Addresses(*args, **kwargs)
create(customer_name, street, city, region, postal_code, iso_country, friendly_name=None)

Create an Address.

Parameters:
  • customer_name (str) – Your customer’s name
  • street (str) – The number and street of your address
  • city (str) – The city of you or your customer’s address
  • region (str) – The region or state
  • postal_code (str) – The postal code of your address
  • iso_country (str) – The ISO 3166-1 alpha-2 (two-character) country code, e.g. ‘US’ or ‘AU’
  • friendly_name (str) – A user-defined name for this address (optional; up to 64 characters)
delete(sid)

Delete an Address.

Parameters:sid (str) – The sid of the Address to delete.
update(sid, **kwargs)

Update an Address with the given parameters.

Parameters are described above in create(), with the exception that iso_country cannot be updated on an existing Address (create a new one instead).

class twilio.rest.resources.Address(parent, sid)

An Address resource. See https://www.twilio.com/docs/api/rest/address

friendly_name

A human-readable description of this address. Maximum 64 characters.

customer_name

Your or your customer’s name or business name.

street

The number and street address where you or your customer are located.

city

The city in which you or your customer are located.

region

The state or region in which you or your customer are located.

postal_code

The postal code in which you or your customer are located.

iso_country

The ISO country code of your or your customer’s address.

update(**kwargs)

Update this phone number instance.

Parameters are as described in Addresses.create(), with the exception that iso_country cannot be updated on an existing Address (create a new one instead).

DependentPhoneNumbers

class twilio.rest.resources.DependentPhoneNumbers(*args, **kwargs)

A list of purchased phone numbers that depend on a particular Address.

Included numbers are those that require an address on file and have no other candidate addresses of the appropriate type (local, foreign) associated with the owning account.

If this list has entries for a given Address, that address cannot be deleted until the numbers are released from your account or alternate addresses are provided to satisfy the requirements.

This resource is read-only and cannot be updated or deleted, but will reflect the current state of the owning account’s addresses (i.e. if you add another address that satisfies a number’s requirements, it will not appear in subsequent requests to this list resource).

class twilio.rest.resources.DependentPhoneNumber(parent, sid)

A purchased phone number that depends on a particular Address.

Attributes are the same as PhoneNumber.

DependentPhoneNumbers are a read-only resource and cannot be updated or deleted.

Applications

class twilio.rest.resources.Applications(*args, **kwargs)
create(**kwargs)

Create an Application with any of these optional parameters.

Parameters:
  • friendly_name – A human readable description of the application, with maximum length 64 characters.
  • api_version – Requests to this application’s URLs will start a new TwiML session with this API version. Either 2010-04-01 or 2008-08-01.
  • voice_url – The URL that Twilio should request when somebody dials a phone number assigned to this application.
  • voice_method – The HTTP method that should be used to request the VoiceUrl. Either GET or POST.
  • voice_fallback_url – A URL that Twilio will request if an error occurs requesting or executing the TwiML defined by VoiceUrl.
  • voice_fallback_method – The HTTP method that should be used to request the VoiceFallbackUrl. Either GET or POST.
  • status_callback – The URL that Twilio will request to pass status parameters (such as call ended) to your application.
  • status_callback_method – The HTTP method Twilio will use to make requests to the StatusCallback URL. Either GET or POST.
  • voice_caller_id_lookup – Do a lookup of a caller’s name from the CNAM database and post it to your app. Either true or false.
  • sms_url – The URL that Twilio should request when somebody sends an SMS to a phone number assigned to this application.
  • sms_method – The HTTP method that should be used to request the SmsUrl. Either GET or POST.
  • sms_fallback_url – A URL that Twilio will request if an error occurs requesting or executing the TwiML defined by SmsUrl.
  • sms_fallback_method – The HTTP method that should be used to request the SmsFallbackUrl. Either GET or POST.
  • sms_status_callback – Twilio will make a POST request to this URL to pass status parameters (such as sent or failed) to your application if you specify this application’s Sid as the ApplicationSid on an outgoing SMS request.
delete(sid)

Delete an Application

list(**kwargs)

Returns a page of Application resources as a list. For paging information see ListResource

Parameters:friendly_name (date) – List applications with this friendly name
update(sid, **kwargs)

Update an Application with the given parameters.

All the parameters are describe above in create()

class twilio.rest.resources.Application(parent, sid)

An application resource

sid

A 34 character string that uniquely identifies this application.

date_created

The date that this application was created, in GMT in RFC 2822 format

date_updated

The date that this application was last updated, in GMT in RFC 2822 format.

friendly_name

A human readable description of this application, up to 64 characters long. By default the FriendlyName is your email address.

status

The status of this account. Usually active, but can be suspended if you’ve been bad, or closed if you’ve been horrible.

api_version

Requests to this application will start a new TwiML session with this API version.

voice_url

URL Twilio will request when a phone number assigned to this application receives a call.

voice_method

The HTTP method Twilio will use when requesting the above Url. Either GET or POST.

voice_fallback_url

The URL that Twilio will request if an error occurs retrieving or executing the TwiML requested by Url.

voice_fallback_method

The HTTP method Twilio will use when requesting the VoiceFallbackUrl. Either GET or POST.

status_callback

The URL that Twilio will request to pass status parameters (such as call ended) to your application.

status_callback_method

The HTTP method Twilio will use to make requests to the StatusCallback URL. Either GET or POST.

voice_caller_id_lookup

Look up the caller’s caller-ID name from the CNAM database (additional charges apply). Either true or false.

sms_url

The URL Twilio will request when a phone number assigned to this application receives an incoming SMS message.

sms_method

The HTTP method Twilio will use when making requests to the SmsUrl. Either GET or POST.

sms_fallback_url

The URL that Twilio will request if an error occurs retrieving or executing the TwiML from SmsUrl.

sms_fallback_method

The HTTP method Twilio will use when requesting the above URL. Either GET or POST.

sms_status_callback

Twilio will make a POST request to this URL to pass status parameters (such as sent or failed) to your application if you specify this application’s Sid as the ApplicationSid on an outgoing SMS request.

uri

The URI for this resource, relative to https://api.twilio.com

delete()

Delete this application

update(**kwargs)

Update this application

Calls

class twilio.rest.resources.Calls(*args, **kwargs)

A list of Call resources

cancel(sid)

If this call is queued or ringing, cancel the call. Will not affect in-progress calls.

Parameters:sid – A Call Sid for a specific call
Returns:Updated Call resource
create(to, from_, url, status_method=None, status_events=None, **kwargs)

Make a phone call to a number.

Parameters:
  • to (str) – The phone number to call
  • from_ (str) – The caller ID (must be a verified Twilio number)
  • url (str) – The URL to read TwiML from when the call connects
  • method (None (defaults to 'POST'), 'GET', or 'POST') – The HTTP method Twilio should use to request the url
  • fallback_url (str) – A URL that Twilio will request if an error occurs requesting or executing the TwiML at url
  • fallback_method (None (will make 'POST' request), 'GET', or 'POST') – The HTTP method that Twilio should use to request the fallback_url
  • status_callback (str) – A URL that Twilio will request when the call ends to notify your app.
  • status_method (str) – The HTTP method Twilio should use when requesting the above URL.
  • status_events (list) – A list of call progress events Twilio should send status callback requests on. One or more of: ‘initiated’, ‘ringing’, ‘answered’, ‘completed’. Defaults to [‘completed’] if not provided. ‘completed’ events are sent free of charge; see twilio.com for current pricing on others.
  • if_machine (None, 'Continue', or 'Hangup') – Tell Twilio to try and determine if a machine (like voicemail) or a human has answered the call. See more in our answering machine documentation.
  • send_digits (None or any combination of (0-9), '#', '*' or 'w' (to insert a half second pause).) – A string of keys to dial after connecting to the number.
  • timeout (int) – The integer number of seconds that Twilio should allow the phone to ring before assuming there is no answer.
  • application_sid (str) – The 34 character sid of the application Twilio should use to handle this phone call. Should not be used in conjunction with the url parameter.
Returns:

A Call object

create_instance(body)

Create an InstanceResource via a POST to the List Resource

Parameters:body (dict) – Dictionary of POST data
delete(sid)

Delete the given Call record from Twilio.

delete_instance(sid)

Delete an InstanceResource via DELETE

body: string – HTTP Body for the quest

feedback(sid, quality_score, issue=None)

Create feedback for the given call.

Parameters:
  • sid – A Call Sid for a specific call
  • quality_score – The quality of the call
  • issue – A list of issues experienced during the call
Returns:

A CallFeedback object

get(sid)

Get an instance resource by its sid

Usage:

message = client.messages.get("SM1234")
print message.body
Return type:InstanceResource
Raises:a TwilioRestException if a resource with that sid does not exist, or the request fails
get_instance(sid)

Request the specified instance resource

get_instances(params)

Query the list resource for a list of InstanceResources.

Raises a TwilioRestException if requesting a page of results that does not exist.

Parameters:
  • params (dict) – List of URL parameters to be included in request
  • page (int) – The page of results to retrieve (most recent at 0)
  • page_size (int) – The number of results to be returned.
Returns:

– the list of resources

hangup(sid)

If this call is currently active, hang up the call. If this call is scheduled to be made, remove the call from the queue.

Parameters:sid – A Call Sid for a specific call
Returns:Updated Call resource
iter(*args, **kwargs)

Returns an iterator of Call resources.

Parameters:
  • after (date) – Only list calls started after this datetime
  • before (date) – Only list calls started before this datetime
list(*args, **kwargs)

Returns a page of Call resources as a list. For paging informtion see ListResource

Parameters:
  • after (date) – Only list calls started after this datetime
  • before (date) – Only list calls started before this datetime
request(method, uri, **kwargs)

Send an HTTP request to the resource.

Raises:a TwilioRestException
route(sid, url, method='POST')

Route the specified Call to another url.

Parameters:
  • sid – A Call Sid for a specific call
  • url – A valid URL that returns TwiML.
  • method – The HTTP method Twilio uses when requesting the URL.
Returns:

Updated Call resource

update_instance(sid, body)

Update an InstanceResource via a POST

sid: string – String identifier for the list resource body: dictionary – Dict of items to POST

class twilio.rest.resources.Call(parent, sid)

A call resource

sid

A 34 character string that uniquely identifies this resource.

parent_call_sid

A 34 character string that uniquely identifies the call that created this leg.

date_created

The date that this resource was created, given as GMT in RFC 2822 format.

date_updated

The date that this resource was last updated, given as GMT in RFC 2822 format.

account_sid

The unique id of the Account responsible for creating this call.

to

The phone number that received this call. e.g., +16175551212 (E.164 format)

from_

The phone number that made this call. e.g., +16175551212 (E.164 format)

phone_number_sid

If the call was inbound, this is the Sid of the IncomingPhoneNumber that received the call. If the call was outbound, it is the Sid of the OutgoingCallerId from which the call was placed.

status

A string representing the status of the call. May be QUEUED, RINGING, IN-PROGRESS, COMPLETED, FAILED, BUSY or NO_ANSWER.

start_time

The start time of the call, given as GMT in RFC 2822 format. Empty if the call has not yet been dialed.

end_time

The end time of the call, given as GMT in RFC 2822 format. Empty if the call did not complete successfully.

duration

The length of the call in seconds. This value is empty for busy, failed, unanswered or ongoing calls.

price

The charge for this call in USD. Populated after the call is completed. May not be immediately available.

direction

A string describing the direction of the call. inbound for inbound calls, outbound-api for calls initiated via the REST API or outbound-dial for calls initiated by a <Dial> verb.

answered_by

If this call was initiated with answering machine detection, either human or machine. Empty otherwise.

forwarded_from

If this call was an incoming call forwarded from another number, the forwarding phone number (depends on carrier supporting forwarding). Empty otherwise.

caller_name

If this call was an incoming call from a phone number with Caller ID Lookup enabled, the caller’s name. Empty otherwise.

cancel()

If the called is queued or rining, cancel the calls. Will not affect in progress calls

delete()

Delete the specified Call record from Twilio.

hangup()

If this call is currenlty active, hang up the call. If this call is scheduled to be made, remove the call from the queue

route(**kwargs)

Route the specified Call to another url.

Parameters:
  • url – A valid URL that returns TwiML.
  • method – HTTP method Twilio uses when requesting the above URL.

Caller Ids

class twilio.rest.resources.CallerIds(*args, **kwargs)

A list of CallerId resources

delete(sid)

Deletes a specific CallerId from the account.

list(**kwargs)
Parameters:
  • phone_number – Show caller ids with this phone number.
  • friendly_name – Show caller ids with this friendly name.
update(sid, **kwargs)

Update a specific CallerId

validate(phone_number, **kwargs)

Begin the validation process for the given number.

Returns a dictionary with the following keys

account_sid: The unique id of the Account to which the Validation Request belongs.

phone_number: The incoming phone number being validated, formatted with a ‘+’ and country code e.g., +16175551212

friendly_name: The friendly name you provided, if any.

validation_code: The 6 digit validation code that must be entered via the phone to validate this phone number for Caller ID.

Parameters:
  • phone_number – The phone number to call and validate
  • friendly_name – A description for the new caller ID
  • call_delay – Number of seconds to delay the validation call.
  • extension – Digits to dial after connecting the validation call.
Returns:

A response dictionary

class twilio.rest.resources.CallerId(parent, sid)
sid

A 34 character string that uniquely identifies this resource.

date_created

The date that this resource was created, given in RFC 2822 format.

date_updated

The date that this resource was last updated, given in RFC 2822 format.

friendly_name

A human readable descriptive text for this resource, up to 64 characters long. By default, the FriendlyName is a nicely formatted version of the phone number.

account_sid

The unique id of the Account responsible for this Caller Id.

phone_number

The incoming phone number. Formatted with a ‘+’ and country code e.g., +16175551212 (E.164 format).

uri

The URI for this resource, relative to https://api.twilio.com.

delete()

Deletes this caller ID from the account.

update(**kwargs)

Update the CallerId

Conferences

class twilio.rest.resources.Conferences(*args, **kwargs)
list(*args, **kwargs)

Return a list of Conference resources

Parameters:
  • status – Show conferences with this status
  • friendly_name – Show conferences with this exact friendly_name
  • updated_after (date) – List conferences updated after this date
  • updated_before (date) – List conferences updated before this date
  • created_after (date) – List conferences created after this date
  • created_before (date) – List conferences created before this date
class twilio.rest.resources.Conference(parent, sid)
sid

A 34 character string that uniquely identifies this conference.

friendly_name

A user provided string that identifies this conference room.

status

A string representing the status of the conference. May be init, in-progress, or completed.

date_created

The date that this conference was created, given as GMT in RFC 2822 format.

date_updated

The date that this conference was last updated, given as GMT in RFC 2822 format.

account_sid

The unique id of the Account responsible for creating this conference.

uri

The URI for this resource, relative to https://api.twilio.com.

participants

The Participants resource, listing people currently in this conference

Connect Apps

class twilio.rest.resources.ConnectApps(*args, **kwargs)

A list of Connect App resources

list(**kwargs)

Returns a page of ConnectApp resources as a list. For paging informtion see ListResource

class twilio.rest.resources.ConnectApp(parent, sid)

An authorized connect app

sid

A 34 character string that uniquely identifies this resource.

date_created

The date that this resource was created, given as GMT in RFC 2822 format.

date_updated

The date that this resource was last updated, given as GMT in RFC 2822 format.

account_sid

The unique id of the Account responsible for creating this call.

permissions

The list of permissions that your ConnectApp requests.

friendly_name

A human readable name for this resource.

description

A more detailed human readable description of this resource.

company_name

The company name set for this Connect App.

homepage_url

The public URL where users can obtain more information about this Connect App.

authorize_redirect_url

The URL the user’s browser will redirect to after Twilio authenticates the user and obtains authorization for this Connect App.

deauthorize_callback_url

The URL to which Twilio will send a request when a user de-authorizes this Connect App.

deauthorize_callback_method

The HTTP method to be used when making a request to the deauthorize callback url.

uri

The URI for this resource, relative to https://api.twilio.com.

Notifications

class twilio.rest.resources.Notifications(*args, **kwargs)
delete(sid)

Delete a given Notificiation

list(*args, **kwargs)

Returns a page of Notification resources as a list. For paging information see ListResource.

NOTE: Due to the potentially voluminous amount of data in a notification, the full HTTP request and response data is only returned in the Notification instance resource representation.

Parameters:
  • after (date) – Only list notifications logged after this datetime
  • before (date) – Only list notifications logger before this datetime
  • log_level – If 1, only shows errors. If 0, only show warnings
class twilio.rest.resources.Notification(parent, sid)
sid

A 34 character string that uniquely identifies this resource.

date_created

The date that this resource was created, given in RFC 2822 format.

date_updated

The date that this resource was last updated, given in RFC 2822 format.

account_sid

The unique id of the Account responsible for this notification.

call_sid

CallSid is the unique id of the call during which the notification was generated. Empty if the notification was generated by the REST API without regard to a specific phone call.

api_version

The version of the Twilio in use when this notification was generated.

log

An integer log level corresponding to the type of notification: 0 is ERROR, 1 is WARNING.

error_code

A unique error code for the error condition. You can lookup errors, with possible causes and solutions, in our Error Dictionary.

more_info

A URL for more information about the error condition. The URL is a page in our Error Dictionary.

message_text

The text of the notification.

message_date

The date the notification was actually generated, given in RFC 2822 format. Due to buffering, this may be slightly different than the DateCreated date.

request_url

The URL of the resource that generated the notification. If the notification was generated during a phone call: This is the URL of the resource on YOUR SERVER that caused the notification. If the notification was generated by your use of the REST API: This is the URL of the REST resource you were attempting to request on Twilio’s servers.

request_method

The HTTP method in use for the request that generated the notification. If the notification was generated during a phone call: The HTTP Method use to request the resource on your server. If the notification was generated by your use of the REST API: This is the HTTP method used in your request to the REST resource on Twilio’s servers.

request_variables

The Twilio-generated HTTP GET or POST variables sent to your server. Alternatively, if the notification was generated by the REST API, this field will include any HTTP POST or PUT variables you sent to the REST API.

response_headers

The HTTP headers returned by your server.

response_body

The HTTP body returned by your server.

uri

The URI for this resource, relative to https://api.twilio.com

delete()

Delete this notification

Participants

class twilio.rest.resources.Participants(*args, **kwargs)
delete(call_sid)

Remove the participant from the given conference

kick(call_sid)

Remove the participant from the given conference

list(**kwargs)

Returns a list of Participant resources in the given conference

Parameters:
  • conference_sid – Conference this participant is part of
  • muted (boolean) – If True, only show participants who are muted
mute(call_sid)

Mute the given participant

unmute(call_sid)

Unmute the given participant

update(sid, **kwargs)
Parameters:
  • sid – Participant identifier
  • muted (boolean) – If true, mute this participant
class twilio.rest.resources.Participant(parent, sid)
call_sid

A 34 character string that uniquely identifies the call that is connected to this conference

conference_sid

A 34 character string that identifies the conference this participant is in

date_created

The date that this resource was created, given in RFC 2822 format.

date_updated

The date that this resource was last updated, given in RFC 2822 format.

account_sid

The unique id of the Account that created this conference

muted

true if this participant is currently muted. false otherwise.

start_conference_on_enter

Was the startConferenceOnEnter attribute set on this participant (true or false)?

end_conference_on_exit

Was the endConferenceOnExit attribute set on this participant (true or false)?

uri

The URI for this resource, relative to https://api.twilio.com.

kick()

Remove the participant from the given conference

mute()

Mute the participant

unmute()

Unmute the participant

Phone Numbers

class twilio.rest.resources.PhoneNumbers(base_uri, auth, timeout=<Unset Timeout Value>)
delete(sid)

Release this phone number from your account. Twilio will no longer answer calls to this number, and you will stop being billed the monthly phone number fees. The phone number will eventually be recycled and potentially given to another customer, so use with care. If you make a mistake, contact us... we may be able to give you the number back.

list(type=None, **kwargs)
Parameters:
  • phone_number – Show phone numbers that match this pattern.
  • friendly_name – Show phone numbers with this friendly name
  • type – Filter numbers by type. Available types are ‘local’, ‘mobile’, or ‘tollfree’

You can specify partial numbers and use ‘*’ as a wildcard.

purchase(status_callback_url=None, **kwargs)

Attempt to purchase the specified number. The only required parameters are either phone_number or area_code

Returns:Returns a PhoneNumber instance on success, False on failure
Raises:A TypeError if neither phone_number or area_code

is specified.

search(**kwargs)
Parameters:
  • type – The type of phone number to search for.
  • country (str) – Only show numbers for this country (iso2)
  • region (str) – When searching the US, show numbers in this state
  • postal_code (str) – Only show numbers in this area code
  • rate_center (str) – US only.
  • near_lat_long (str) – Find close numbers within Distance miles. Should be string of format “{lat},{long}”
  • distance (integer) – Search radius for a Near- query in miles.
  • beta (boolean) – Whether to include numbers new to the Twilio platform.
transfer(sid, account_sid)

Transfer the phone number with sid from the current account to another identified by account_sid

update(sid, **kwargs)

Update this phone number instance

class twilio.rest.resources.PhoneNumber(parent, sid)

An IncomingPhoneNumber object

sid

A 34 character string that uniquely identifies this resource.

date_created

The date that this resource was created, given as GMT RFC 2822 format.

date_updated

The date that this resource was last updated, in GMT RFC 2822 format.

friendly_name

A human readable descriptive text for this resource, up to 64 characters long. By default, the FriendlyName is a nicely formatted version of the phone number.

account_sid

The unique id of the Account responsible for this phone number.

phone_number

The incoming phone number. e.g., +16175551212 (E.164 format)

api_version

Calls to this phone number will start a new TwiML session with this API version.

voice_caller_id_lookup

Look up the caller’s caller-ID name from the CNAM database (additional charges apply). Either true or false.

voice_url

The URL Twilio will request when this phone number receives a call.

voice_method

The HTTP method Twilio will use when requesting the above Url. Either GET or POST.

voice_fallback_url

The URL that Twilio will request if an error occurs retrieving or executing the TwiML requested by Url.

voice_fallback_method

The HTTP method Twilio will use when requesting the VoiceFallbackUrl. Either GET or POST.

status_callback

The URL that Twilio will request to pass status parameters (such as call ended) to your application.

status_callback_method

The HTTP method Twilio will use to make requests to the StatusCallback URL. Either GET or POST.

sms_url

The URL Twilio will request when receiving an incoming SMS message to this number.

sms_method

The HTTP method Twilio will use when making requests to the SmsUrl. Either GET or POST.

sms_fallback_url

The URL that Twilio will request if an error occurs retrieving or executing the TwiML from SmsUrl.

sms_fallback_method

The HTTP method Twilio will use when requesting the above URL. Either GET or POST.

uri

The URI for this resource, relative to https://api.twilio.com.

beta

(boolean) Phone numbers new to the Twilio platform are marked as beta.

delete()

Release this phone number from your account. Twilio will no longer answer calls to this number, and you will stop being billed the monthly phone number fees. The phone number will eventually be recycled and potentially given to another customer, so use with care. If you make a mistake, contact us... we may be able to give you the number back.

load(entries)

Set the proper Account owner of this phone number

transfer(account_sid)

Transfer the phone number with sid from the current account to another identified by account_sid

update(**kwargs)

Update this phone number instance.

class twilio.rest.resources.AvailablePhoneNumber(parent)

An available phone number resource

friendly_name

A nicely-formatted version of the phone number.

phone_number

The phone number, in E.164 (i.e. “+1”) format.

lata

The LATA of this phone number.

rate_center

The rate center of this phone number.

latitude

The latitude coordinate of this phone number.

longitude

The longitude coordinate of this phone number.

region

The two-letter state or province abbreviation of this phone number.

postal_code

The postal (zip) code of this phone number.

iso_country

The country for this number

address_requirements

Whether the phone number requires you or your customer to have an Address registered with Twilio. Possible values are ‘none’, ‘any’, ‘local’, or ‘foreign’.

beta

(boolean) Phone numbers new to the Twilio platform are marked as beta.

Queues

class twilio.rest.resources.Queues(*args, **kwargs)
create(name, **kwargs)

Create an Queue with any of these optional parameters.

Parameters:
  • name – A human readable description of the application, with maximum length 64 characters.
  • max_size – The limit on calls allowed into the queue (optional)
delete(sid)

Delete a Queue. Can only be run on empty queues.

Parameters:sid – String identifier for a Queue resource
list(**kwargs)

Returns a page of Queue resources as a list sorted by DateUpdated. For paging informtion see ListResource

update(sid, **kwargs)

Update a Queue

Parameters:
  • sid – String identifier for a Queue resource
  • friendly_name – A new friendly name for this queue
  • max_size – A new max size. Changing a max size to less than the current size results in the queue rejecting incoming requests until it shrinks below the new max size
class twilio.rest.resources.Queue(parent, sid)

An instance of a Queue

sid

A 34 character string that uniquely identifies this queue.

friendly_name

A user-provided string that identifies this queue.

current_size

The count of calls currently in the queue.

max_size

The upper limit of calls allowed to be in the queue. unlimited is an option. The default is 100.

average_wait_time

The average wait time of the members of this queue in seconds. This is calculated at the time of the request.

uri

The URI for this resource, relative to https://api.twilio.com.

queue_members

A Members object holding the Member objects in this queue.

delete()

Delete this queue. Can only be run on empty queues.

update(**kwargs)

Update this queue

Parameters:
  • friendly_name – A new friendly name for this queue
  • max_size – A new max size. Changing a max size to less than the current size results in the queue rejecting incoming requests until it shrinks below the new max size

Queue Members

class twilio.rest.resources.Members(*args, **kwargs)

A list of Member objects

dequeue(url, call_sid='Front', **kwargs)

Dequeues a member from the queue and have the member’s call begin executing the TwiML document at the url.

Parameters:
  • call_sid – Call sid specifying the member, if not given, the member at the front of the queue will be used
  • url – url of the TwiML document to be executed.
list(**kwargs)

Returns a list of Member resources in the given queue

Parameters:queue_sidQueue this participant is part of
class twilio.rest.resources.Member(parent, sid)

A Member of a queue

call_sid

A 34 character string that uniquely identifies the call that is enqueued.

date_enqueued

The date that the member was enqueued, given in RFC 2822 format.

wait_time

The number of seconds the member has been in the queue.

position

This member’s current position in the queue.

uri

The URI for this resource, relative to https://api.twilio.com.

Recordings

class twilio.rest.resources.Recordings(*args, **kwargs)
delete(sid)

Delete the given recording

iter(*args, **kwargs)

Returns an iterator of Recording resources.

Parameters:
  • after (date) – Only list recordings logged after this datetime
  • before (date) – Only list recordings logger before this datetime
list(*args, **kwargs)

Returns a page of Recording resources as a list. For paging information see ListResource.

Parameters:
  • after (date) – Only list recordings logged after this datetime
  • before (date) – Only list recordings logger before this datetime
  • call_sid – Only list recordings from this Call
class twilio.rest.resources.Recording(*args, **kwargs)
sid

A 34 character string that uniquely identifies this resource.

date_created

The date that this resource was created, given in RFC 2822 format.

date_updated

The date that this resource was last updated, given in RFC 2822 format.

account_sid

The unique id of the Account responsible for this recording.

call_sid

The call during which the recording was made.

duration

The length of the recording, in seconds.

api_version

The version of the API in use during the recording.

uri

The URI for this resource, relative to https://api.twilio.com

subresource_uris

The list of subresources under this account

formats

A dictionary of the audio formats available for this recording

{
    "wav": "http://www.dailywav.com/0112/noFateButWhatWeMake.wav",
    "mp3": "https://api.twilio.com/cowbell.mp3",
}
delete()

Delete this recording

Sandbox

class twilio.rest.resources.Sandboxes(*args, **kwargs)
get()

Request the specified instance resource

update(**kwargs)

Update your Twilio Sandbox

class twilio.rest.resources.Sandbox(parent, sid)
pin

An 8 digit number that gives access to this sandbox.

account_sid

The unique id of the Account connected to this sandbox.

phone_number

The phone number of the sandbox. Formatted with a ‘+’ and country code e.g., +16175551212 (E.164 format).

voice_url

The URL Twilio will request when the sandbox number is called.

voice_method

The HTTP method to use when requesting the above URL. Either GET or POST.

sms_url

The URL Twilio will request when receiving an incoming SMS message to the sandbox number.

sms_method

The HTTP method to use when requesting the sms URL. Either GET or POST.

date_created

The date that this resource was created, given in RFC 2822 format.

date_updated

The date that this resource was last updated, given in RFC 2822 format.

uri

The URI for this resource, relative to https://api.twilio.com

update(**kwargs)

Update your Twilio Sandbox

Short Codes

class twilio.rest.resources.ShortCodes(*args, **kwargs)
list(**kwargs)

Returns a page of ShortCode resources as a list. For paging information see ListResource.

Parameters:
  • short_code – Only show the ShortCode resources that match this pattern. You can specify partial numbers and use ‘*’ as a wildcard for any digit.
  • friendly_name – Only show the ShortCode resources with friendly names that exactly match this name.
update(sid, url=None, method=None, fallback_url=None, fallback_method=None, **kwargs)

Update a specific ShortCode, by specifying the sid.

Parameters:
  • friendly_name – Description of the short code, with maximum length 64 characters.
  • api_version – SMSs to this short code will start a new TwiML session with this API version.
  • url – The URL that Twilio should request when somebody sends an SMS to the short code.
  • method – The HTTP method that should be used to request the url.
  • fallback_url – A URL that Twilio will request if an error occurs requesting or executing the TwiML at the url.
  • fallback_method – The HTTP method that should be used to request the fallback_url.
class twilio.rest.resources.ShortCode(parent, sid)
sid

A 34 character string that uniquely identifies this resource.

date_created

The date that this resource was created, given in RFC 2822 format.

date_updated

The date that this resource was last updated, given in RFC 2822 format.

friendly_name

A human readable descriptive text for this resource, up to 64 characters long. By default, the friendly_name is just the short code.

account_sid

The unique id of the Account that owns this short code.

short_code

The short code. e.g., 894546.

api_version

SMSs to this short code will start a new TwiML session with this API version.

sms_url

The URL Twilio will request when receiving an incoming SMS message to this short code.

sms_method

The HTTP method Twilio will use when making requests to the sms_url. Either GET or POST.

sms_fallback_url

The URL that Twilio will request if an error occurs retrieving or executing the TwiML from sms_url.

sms_fallback_method

The HTTP method Twilio will use when requesting the above URL. Either GET or POST.

uri

The URI for this resource, relative to https://api.twilio.com.

SMS Messages

class twilio.rest.resources.SmsMessages(*args, **kwargs)
create(from_=None, **kwargs)

Create and send a SMS Message.

Parameters:
  • to (str) – The destination phone number.
  • from_ (str) – The phone number sending this message (must be a verified Twilio number)
  • body (str) – The message you want to send, limited to 160 characters.
  • status_callback – A URL that Twilio will POST to when your message is processed.
  • application_sid (str) – The 34 character sid of the application Twilio should use to handle this phone call.

Usage:

instance

alias of SmsMessage

list(*args, **kwargs)

Returns a page of SmsMessage resources as a list. For paging information see ListResource.

Parameters:
  • to – Only show SMS messages to this phone number.
  • from – Only show SMS messages from this phone number.
  • after (date) – Only list SMS messages sent after this date.
  • before (date) – Only list SMS message sent before this date.
  • date_sent (date) – Only list SMS message sent on this date.
  • from_ – Only show SMS messages from this phone number.
  • after – Only list SMS messages logged after this datetime
  • before – Only list SMS messages logged before this datetime
class twilio.rest.resources.SmsMessage(parent, sid)

An instance of an SMS Message

sid

A 34 character string that uniquely identifies this resource.

date_created

The date that this resource was created, given in RFC 2822 format.

date_updated

The date that this resource was last updated, given in RFC 2822 format.

date_sent

The date that the SMS was sent, given in RFC 2822 format.

account_sid

The unique id of the Account that sent this SMS message.

from

The phone number that initiated the message in E.164 format. For incoming messages, this will be the remote phone. For outgoing messages, this will be one of your Twilio phone numbers.

to

The phone number that received the message in E.164 format. For incoming messages, this will be one of your Twilio phone numbers. For outgoing messages, this will be the remote phone.

body

The text body of the SMS message.

status

The status of this SMS message. Either queued, sending, sent, or failed.

direction

The direction of this SMS message. incoming for incoming messages, outbound-api for messages initiated via the REST API, outbound-call for messages initiated during a call or outbound-reply for messages initiated in response to an incoming SMS.

price

The amount billed for the message.

api_version

The version of the Twilio API used to process the SMS message.

uri

The URI for this resource, relative to https://api.twilio.com

Transcriptions

class twilio.rest.resources.Transcriptions(*args, **kwargs)
delete(sid)

Delete the given transcription

list(**kwargs)

Return a list of Transcription resources

class twilio.rest.resources.Transcription(parent, sid)
sid

A 34 character string that uniquely identifies this resource.

date_created

The date that this resource was created, given in RFC 2822 format.

date_updated

The date that this resource was last updated, given in RFC 2822 format.

account_sid

The unique id of the Account responsible for this transcription.

status

A string representing the status of the transcription: in-progress, completed or failed.

recording_sid

The unique id of the Recording this Transcription was made of.

duration

The duration of the transcribed audio, in seconds.

transcription_text

The text content of the transcription.

price

The charge for this transcript in USD. Populated after the transcript is completed. Note, this value may not be immediately available.

uri

The URI for this resource, relative to https://api.twilio.com

delete()

Delete this transcription