Call Resource
A Call is an object that represents a connection between a telephone and Twilio.
Using this resource, you can initiate a call, fetch information about a completed call, fetch a list of calls made to and from your account, redirect or end a call that is in progress, and delete records of past calls from your account.
An inbound call occurs when a person calls one of your Twilio phone numbers, client connections, or SIP-enabled endpoints. An outbound call happens when you initiate a call from a Twilio phone number to an outside phone number, client, or SIP domain.
You can initiate an outbound call by POSTing to the Call resource, creating a new call.
You can also initiate a call from an active call (e.g., forwarding to another number or dialing into a conference) by including TwiML’s <Dial> verb in your TwiML application. However, the only way to initiate a call directly from Twilio is with an API request.
Call properties
Resource Properties in REST API format | |
---|---|
sid
|
The unique string that we created to identify this Call resource. |
date_created
|
The date and time in GMT that this resource was created specified in RFC 2822 format. |
date_updated
|
The date and time in GMT that this resource was last updated, specified in RFC 2822 format. |
parent_call_sid
|
The SID that identifies the call that created this leg. |
account_sid
|
The SID of the Account that created this Call resource. |
to
|
The phone number, SIP address, Client identifier or SIM SID that received this call. Phone numbers are in E.164 format (e.g., +16175551212). SIP addresses are formatted as |
to_formatted
|
The phone number, SIP address or Client identifier that received this call. Formatted for display. Non-North American phone numbers are in E.164 format (e.g., +442071838750). |
from
|
The phone number, SIP address, Client identifier or SIM SID that made this call. Phone numbers are in E.164 format (e.g., +16175551212). SIP addresses are formatted as |
from_formatted
|
The calling phone number, SIP address, or Client identifier formatted for display. Non-North American phone numbers are in E.164 format (e.g., +442071838750). |
phone_number_sid
|
If the call was inbound, this is the SID of the IncomingPhoneNumber resource that received the call. If the call was outbound, it is the SID of the OutgoingCallerId resource from which the call was placed. |
status
|
The status of this call. Can be: |
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 time the call ended, 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 the currency associated with the account. Populated after the call is completed. May not be immediately available. |
price_unit
|
The currency in which |
direction
|
A string describing the direction of the call. Can be: |
answered_by
|
Either |
api_version
|
The API version used to create the call. |
forwarded_from
|
The forwarding phone number if this call was an incoming call forwarded from another number (depends on carrier supporting forwarding). Otherwise, empty. |
group_sid
|
The Group SID associated with this call. If no Group is associated with the call, the field is empty. |
caller_name
|
The caller's name if this call was an incoming call to a phone number with caller ID Lookup enabled. Otherwise, empty. |
queue_time
|
The wait time in milliseconds before the call is placed. |
trunk_sid
|
The unique identifier of the trunk resource that was used for this call. The field is empty if the call was not made using a SIP trunk or if the call is not terminated. |
uri
|
The URI of this resource, relative to |
subresource_uris
|
A list of subresources available to this call, identified by their URIs relative to |
Call status values
The following are the possible values for the Status
parameter:
Status | Description |
---|---|
queued |
The call is ready and waiting in line before dialing. |
ringing |
The call is currently ringing. |
in-progress |
The call was answered and is currently in progress. |
canceled |
The call was hung up while it was queued or ringing. |
completed |
The call was answered and has ended normally. |
busy |
The caller received a busy signal. |
no-answer |
There was no answer or the call was rejected. |
failed |
The call could not be completed as dialed, most likely because the phone number was non-existent. |
Create a Call resource
https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls.json
Calls can be made via the REST API to phone numbers, SIP addresses, or client identifiers. To place a new outbound call, make an HTTP POST request to your account’s Call resource.
Parameters
Parameters in REST API format | |
---|---|
account_sid
Path
|
The SID of the Account that will create the resource. |
to
Required
|
The phone number, SIP address, or client identifier to call. |
from
Required
|
The phone number or client identifier to use as the caller id. If using a phone number, it must be a Twilio number or a Verified outgoing caller id for your account. If the |
method
Optional
|
The HTTP method we should use when calling the |
fallback_url
Optional
|
The URL that we call using the |
fallback_method
Optional
|
The HTTP method that we should use to request the |
status_callback
Optional
|
The URL we should call using the |
status_callback_event
Optional
|
The call progress events that we will send to the |
status_callback_method
Optional
|
The HTTP method we should use when calling the |
send_digits
Optional
|
A string of keys to dial after connecting to the number, maximum of 32 digits. Valid digits in the string include: any digit ( |
timeout
Optional
|
The integer number of seconds that we should allow the phone to ring before assuming there is no answer. The default is |
record
Optional
|
Whether to record the call. Can be |
recording_channels
Optional
|
The number of channels in the final recording. Can be: |
recording_status_callback
Optional
|
The URL that we call when the recording is available to be accessed. |
recording_status_callback_method
Optional
|
The HTTP method we should use when calling the |
sip_auth_username
Optional
|
The username used to authenticate the caller making a SIP call. |
sip_auth_password
Optional
|
The password required to authenticate the user account specified in |
machine_detection
Optional
|
Whether to detect if a human, answering machine, or fax has picked up the call. Can be: |
machine_detection_timeout
Optional
|
The number of seconds that we should attempt to detect an answering machine before timing out and sending a voice request with |
recording_status_callback_event
Optional
|
The recording status events that will trigger calls to the URL specified in |
trim
Optional
|
Whether to trim any leading and trailing silence from the recording. Can be: |
caller_id
Optional
|
The phone number, SIP address, or Client identifier that made this call. Phone numbers are in E.164 format (e.g., +16175551212). SIP addresses are formatted as |
machine_detection_speech_threshold
Optional
|
The number of milliseconds that is used as the measuring stick for the length of the speech activity, where durations lower than this value will be interpreted as a human and longer than this value as a machine. Possible Values: 1000-6000. Default: 2400. |
machine_detection_speech_end_threshold
Optional
|
The number of milliseconds of silence after speech activity at which point the speech activity is considered complete. Possible Values: 500-5000. Default: 1200. |
machine_detection_silence_timeout
Optional
|
The number of milliseconds of initial silence after which an |
async_amd
Optional
|
Select whether to perform answering machine detection in the background. Default, blocks the execution of the call until Answering Machine Detection is completed. Can be: |
async_amd_status_callback
Optional
|
The URL that we should call using the |
async_amd_status_callback_method
Optional
|
The HTTP method we should use when calling the |
byoc
Optional
|
The SID of a BYOC (Bring Your Own Carrier) trunk to route this call with. Note that |
call_reason
Optional
|
The Reason for the outgoing call. Use it to specify the purpose of the call that is presented on the called party's phone. (Branded Calls Beta) |
call_token
Optional
|
A token string needed to invoke a forwarded call. A call_token is generated when an incoming call is received on a Twilio number. Pass an incoming call's call_token value to a forwarded call via the call_token parameter when creating a new call. A forwarded call should bear the same CallerID of the original incoming call. |
recording_track
Optional
|
The audio track to record for the call. Can be: |
time_limit
Optional
|
The maximum duration of the call in seconds. Constraints depend on account and configuration. |
url
Required if
twiml,
application_sid
is not passed
|
The absolute URL that returns the TwiML instructions for the call. We will call this URL using the |
twiml
Required if
url,
application_sid
is not passed
|
TwiML instructions for the call Twilio will use without fetching Twiml from url parameter. If both |
application_sid
Required if
url,
twiml
is not passed
|
The SID of the Application resource that will handle the call, if the call will be handled by an application. |
Example 1
Example 2
Example 3
Example 4
StatusCallback
After completing an outbound call, Twilio will make an asynchronous HTTP request to the StatusCallback
URL you specified in your request (if any).
Parameters sent to your StatusCallback URL
When Twilio sends its asynchronous request to your StatusCallback
URL, it includes all of the following parameters:
Parameter | Description |
---|---|
CallSid | A unique identifier for this call, generated by Twilio. |
AccountSid | Your Twilio account ID. It is 34 characters long, and always starts with the letters AC . |
From |
The phone number or client identifier of the party that initiated the call. Phone numbers use E.164 formatting, meaning they start with a + and country code, e.g. Client identifiers begin with the |
To |
The phone number or client identifier of the called party. Phone numbers use E.164 formatting, meaning they start with a Client identifiers begin with the |
CallStatus |
A descriptive status for the call. The value is one of the following: |
ApiVersion |
The version of the Twilio API used to handle this call. For incoming calls, this is determined by the API version set on the dialed number. For outgoing calls, this is the version used in the REST API request of the outgoing call. |
Direction |
A string describing the direction of the call:
|
ForwardedFrom |
This parameter may be set when Twilio receives a forwarded call. The carrier who forwards the call determines the contents of the parameter. Not all carriers support passing this information. Some carriers provide this information when making a direct call to a Twilio number. |
CallerName | This parameter is set when the IncomingPhoneNumber that received the call has set its VoiceCallerIdLookup value to true ($0.01 per lookup). |
ParentCallSid |
A unique identifier for the call that created this leg. If this is the first leg of a call, this parameter is not included. |
StatusCallbackEvent
If you specify any call progress events in the StatusCallbackEvent
parameter, Twilio will make an asynchronous request to the StatusCallback
URL you provided in your POST request.
The call progress events you can specify are:
Event | Description |
---|---|
initiated |
Twilio removes your call from the queue and starts dialing. |
ringing |
The call starts ringing. |
answered |
The call is answered. If this event is specified, Twilio will send an in-progress status. |
completed |
The call is completed, regardless of the termination status (which can be busy , cancelled , completed , failed , or no-answer ). If no StatusCallbackEvent is specified, completed is fired by default. |
When these events occur, Twilio’s StatusCallback
request will also include these additional parameters:
Parameter | Description |
---|---|
CallStatus |
A descriptive status for the call. The value is one of queued , initiated , ringing , in-progress , busy , failed , or no-answer . For more details, see the CallStatus values in our TwiML introduction. |
Duration |
The duration in minutes of the just-completed call; calls are billed by the minute. Only present in the completed event. |
CallDuration |
The duration in seconds of the just-completed call. Only present in the completed event. |
SipResponseCode |
The SIP code that resulted in a failed call. Only present in the |
RecordingUrl |
The URL of the phone call’s recorded audio. This parameter is included only if Record=true is set on the REST API request and does not include recordings initiated in other ways. RecordingUrl is only present in the completed event. The recording file may not yet be accessible when the Status Callback is sent. Note: Use RecordingStatusCallback for reliable notification on when the recording is available for access. |
RecordingSid |
The unique ID of the Recording from this call. RecordingSid is only present with the completed event. |
RecordingDuration |
The duration of the recorded audio (in seconds). RecordingDuration is only present in the completed event. To get a final accurate recording duration after any trimming of silence, use RecordingStatusCallback . |
Timestamp |
The timestamp when the event fired, given as UTC in RFC 2822 format. |
CallbackSource |
A string that describes the source of the webhook. This is provided to help disambiguate why the webhook was made. On Status Callbacks, this value is always call-progress-events . |
SequenceNumber |
The order in which the events were fired, starting from 0 . Although events are fired in order, they are made as separate HTTP requests, and there is no guarantee they will arrive in the same order. |
You can use the StatusCallback
and StatusCallbackEvent
features to track the call status of Programmable Voice calls only.
To learn more about the StatusCallbackEvent
parameter and what you can expect from Twilio during and after an outbound call, check out our overview page on making outbound calls.
RecordingStatusCallback
If you requested a recording of your outbound call and you specified a RecordingStatusCallback
URL, Twilio will make a GET or POST request to that URL when the recording is available.
Twilio will pass along the following parameters to your RecordingStatusCallback
URL:
Parameter | Description |
---|---|
AccountSid |
The unique identifier of the Account responsible for this recording. |
CallSid |
A unique identifier for the call associated with the recording. CallSid will always refer to the parent leg of a two-leg call. |
RecordingSid |
The unique identifier for the recording. |
RecordingUrl |
The URL of the recorded audio. |
RecordingStatus |
The status of the recording. Possible values are: in-progress , completed , absent . |
RecordingDuration |
The length of the recording, in seconds. |
RecordingChannels |
The number of channels in the final recording file as an integer. Possible values are 1 , 2 . |
RecordingStartTime |
The timestamp of when the recording started. |
RecordingSource |
The initiation method used to create this recording. For recordings initiated when Record=true is set on the REST API, OutboundAPI will be returned. |
RecordingTrack |
The audio track recorded. Possible values are inbound , outbound , or both . |
RecordingStatusCallbackEvent
Just as you can specify call progress events with StatusCallbackEvent
, you can also specify which recording status changes should trigger a callback to your application.
Available recording status values are:
Parameter | Description |
---|---|
in-progress |
The recording has started. |
completed |
The recording is complete and available for access. |
absent |
The recording is absent and inaccessible. |
This parameter defaults to completed
. To specify multiple values, separate them with a space.
To pause, resume, or stop recordings, see the Call Recording resource.
Fetch a Call resource
https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json
This API call returns the Call resource of an individual call, identified by its CallSid
. This resource is eventually consistent.
To get real-time call status updates, we recommend using the StatusCallbackEvent on the Outbound API request or the TwiML <Dial> verb statusCallbackEvent attribute for the case of child calls.
Parameters
Parameters in REST API format | |
---|---|
account_sid
Path
|
The SID of the Account that created the Call resource(s) to fetch. |
sid
Path
|
The SID of the Call resource to fetch. |
Example 1
Call Recordings
You can access the Recordings list subresource on any given Call.
The following will return a list of all of the recordings generated with a given call (identified by its CallSid
):
/2010-04-01/Accounts/{YourAccountSid}/Calls/{CallSid}/Recordings
See the Call Recording resource docs for resource properties and response formats.
Call Feedback
You can access call quality feedback information from a given phone call by requesting the Feedback subresource on any Call (identified by its CallSid
):
/2010-04-01/Accounts/{YourAccountSid}/Calls/{CallSid}/Feedback
See the Call Quality Feedback resource documentation for properties and response formats. See also the FeedbackSummary resource for summarized information about call quality.
Read multiple Call resources
https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls.json
Return a list of phone calls made to and from an account, identified by its AccountSid
.
The following query string parameters allow you to filter and limit the list returned to you by the REST API. These parameters are case-sensitive.
Parameters
Parameters in REST API format | |
---|---|
account_sid
Path
|
The SID of the Account that created the Call resource(s) to read. |
to
Optional
|
Only show calls made to this phone number, SIP address, Client identifier or SIM SID. |
from
Optional
|
Only include calls from this phone number, SIP address, Client identifier or SIM SID. |
parent_call_sid
Optional
|
Only include calls spawned by calls with this SID. |
status
Optional
|
The status of the calls to include. Can be: |
start_time
Optional
|
Only include calls that started on this date. Specify a date as |
end_time
Optional
|
Only include calls that ended on this date. Specify a date as |
Example 1
Example 2
Example 3
Example 4
Example 5
Example 6
You can append a .csv
extension to any resource URI to get CSV (Comma Separated Values) representation. Specifying CSV may be especially useful for call logs. Try this:
GET /2010-04-01/Accounts/{AccountSid}/Calls.csv
Read the guide to Returning JSON, CSV, and HTML for more information about all available alternate representations.
Paging
If you are using the Twilio REST API, the list returned to you includes paging information.
If you plan to request more records than will fit on a single page, you can use the provided nextpageuri
rather than incrementing through pages by page number.
Using nextpageuri
for paging ensures that your next request will pick up where you left off. This can help keep you from retrieving duplicate data if you are actively making or receiving calls.
All of the Twilio Helper Libraries handle paging automatically. You do not need to explicitly request individual pages when using a Helper Library to fetch lists of resources.
Update a Call resource
https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json
Updating a Call resource allows you to modify an active call.
Real-time call modification allows you to interrupt an in-progress call and terminate it or have it begin processing TwiML from either a new URL or from the TwiML provided with modification. Call modification is useful for any application where you want to change the behavior of a running call asynchronously, e.g., hold music, call queues, transferring calls, or forcing a hangup.
By POSTing to a specific Call instance, you can redirect a call that is in progress or you can terminate a call.
For step-by-step guidance on modifying in-progress calls, check out the tutorial Modify Calls in Progress in your web language of choice.
Parameters
Parameters in REST API format | |
---|---|
account_sid
Path
|
The SID of the Account that created the Call resource(s) to update. |
sid
Path
|
The Twilio-provided string that uniquely identifies the Call resource to update |
url
Optional
|
The absolute URL that returns the TwiML instructions for the call. We will call this URL using the |
method
Optional
|
The HTTP method we should use when calling the |
status
Optional
|
The new status of the resource. Can be: |
fallback_url
Optional
|
The URL that we call using the |
fallback_method
Optional
|
The HTTP method that we should use to request the |
status_callback
Optional
|
The URL we should call using the |
status_callback_method
Optional
|
The HTTP method we should use when requesting the |
twiml
Optional
|
TwiML instructions for the call Twilio will use without fetching Twiml from url. Twiml and url parameters are mutually exclusive |
time_limit
Optional
|
The maximum duration of the call in seconds. Constraints depend on account and configuration. |
Example 1
Example 2
Example 3
When you redirect an active call to another phone number, Twilio creates an entirely new Call instance for that new phone number. The original call is the parent call, and any additional number dialed establishes a child call. Parent and child calls will have uniquely identifying Call SIDs.
Note that any parent call currently executing a <Dial> is considered in-progress by Twilio. Even if you’ve re-directed your initial call to a new number, the parent call is still active, and thus you must use Status=completed
to end it.
If Enhanced SIP Features is not enabled on your account, unanswered child calls cannot be canceled via the REST API, but the parent call can be modified to point to new TwiML. This action will end the child call.
Example 4
To update a StatusCallback
on a Call, it is required to set the Url
in the same statement.
Delete a Call resource
https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json
This will delete a call record from your account. Once the record is deleted, it will no longer appear in the API and Account Portal logs.
If successful, this DELETE returns an HTTP 204 (No Content) with no body.
Note that an error will occur if you attempt to remove a call record for a call that is actively in progress.
Parameters
Parameters in REST API format | |
---|---|
account_sid
Path
|
The SID of the Account that created the Call resource(s) to delete. |
sid
Path
|
The Twilio-provided Call SID that uniquely identifies the Call resource to delete |
Note: For calls less than 13 months old, resources deleted from this endpoint will also be deleted in Log Archives. Calls older than 13 months can only be deleted via the Bulk Export API.
Example 1
Call resource retention
You are able to retrieve resources via GET to the /Calls
endpoint for 13 months after the resource is created. Records older than thirteen months can only be retrieved via Bulk Export.
We provide a Bulk Export utility in Console and via API. Bulk Export will generate S3 files containing one day of data per file and deliver the download link via webhook, email, or Console.
What's next?
Explore Voice Insights with its Call Insights Event Stream and Call Insights REST API which allow you to see call parameters, investigate call metrics and event timelines, and understand detected quality issues.
Need some help?
We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.