Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Retrieve call logs


Learn to retrieve call logs with Twilio Programmable Voice by sending a GET request to the Calls.json endpoint or fetching a specific call resource by SID. You can use this guide to monitor calls, view call metrics, inspect call history, and troubleshoot call issues.

See Related reference documentation to learn more about the Call resource used in this guide.

(information)

Info

You can see all incoming and outgoing calls, as well as message activity, by viewing a specific phone number in Twilio Console. In Twilio Console, go to Products & services > Numbers & senders(link takes you to an external page), and select a phone number. In the legacy Console(link takes you to an external page), open a phone number and choose the Calls Log or Messages Log tab.


Complete the prerequisites

complete-the-prerequisites page anchor

Complete the Twilio prerequisites

complete-the-twilio-prerequisites page anchor

Complete the language prerequisites

complete-the-language-prerequisites page anchor

Select your programming language and complete the prerequisites:

PythonNode.jsPHPC# or .NETJavaRuby
  • Install Python 3.3 or later(link takes you to an external page).
  • Install Flask(link takes you to an external page) and the Twilio Python Helper Library(link takes you to an external page). Using pip(link takes you to an external page), run the following command:
    pip install flask twilio
  • Install and set up ngrok(link takes you to an external page).

Get credentials and set as environment variables

get-credentials-and-set-as-environment-variables page anchor

Extract your credentials from your Twilio account then save these credentials as environment variables.

Twilio ConsoleLegacy Console
  1. Go to the Twilio Console(link takes you to an external page). The Let's get building page appears.

  2. Click API keys and Auth tokens. The API keys & auth tokens page appears with the Auth Tokens tab selected.

  3. Scroll to your Account SID.

  4. Click the copy button next to your Account SID.

  5. Run the following command, replacing YOUR_ACCOUNT_SID with your Account SID.

    macOS TerminalWindows command linePowerShell
    export TWILIO_ACCOUNT_SID=YOUR_ACCOUNT_SID

    This command creates an environment variable on your development system for your account SID.

  6. To display the Auth Token, click the eye button in the Primary auth token box.

  7. Highlight and copy the Auth Token.

  8. Run the following command, replacing YOUR_AUTH_TOKEN with your Authentication Token.

    macOS TerminalWindows command linePowerShell
    export TWILIO_AUTH_TOKEN=YOUR_AUTH_TOKEN

    This command creates an environment variable on your development system for your auth token.


You can use Twilio's REST API to retrieve logs about the phone calls to and from your Twilio account. If you just want to check a couple logs, however, you should try looking at the voice logs in your Twilio console first.

List all calls for Twilio account

list-all-calls-for-twilio-account page anchor

To list all phone calls for your Twilio account, just call @client.calls.list().

PythonNode.jsPHPC# or .NETJavaRuby

Python only requires the Twilio Python helper library as noted in the prerequisites.

List All Calls ExampleLink to code sample: List All Calls Example
1
# Download the helper library from https://www.twilio.com/docs/python/install
2
import os
3
from twilio.rest import Client
4
5
# Find your Account SID and Auth Token at twilio.com/console
6
# and set the environment variables. See http://twil.io/secure
7
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
8
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
9
client = Client(account_sid, auth_token)
10
11
calls = client.calls.list(limit=20)
12
13
for record in calls:
14
print(record.end)

You can also filter the list results. This example only returns phone calls to the phone number +15558675309 which had a call status of busy but you can filter on other call properties as well.

PythonNode.jsPHPC# or .NETJavaRuby

Python only requires the Twilio Python helper library as noted in the prerequisites.

Retrieve Busy Calls To Specific Number ExampleLink to code sample: Retrieve Busy Calls To Specific Number Example
1
# Download the helper library from https://www.twilio.com/docs/python/install
2
import os
3
from twilio.rest import Client
4
5
# Find your Account SID and Auth Token at twilio.com/console
6
# and set the environment variables. See http://twil.io/secure
7
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
8
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
9
client = Client(account_sid, auth_token)
10
11
calls = client.calls.list(to="+15558675310", status="busy", limit=20)
12
13
for record in calls:
14
print(record.end)

To retrieve data about a specific call, you can get that CallSid directly.

PythonNode.jsPHPC# or .NETJavaRuby

Python only requires the Twilio Python helper library as noted in the prerequisites.

1
# Download the helper library from https://www.twilio.com/docs/python/install
2
import os
3
from twilio.rest import Client
4
5
# Find your Account SID and Auth Token at twilio.com/console
6
# and set the environment variables. See http://twil.io/secure
7
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
8
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
9
client = Client(account_sid, auth_token)
10
11
call = client.calls("CA42ed11f93dc08b952027ffbc406d0868").fetch()
12
13
print(call.to)

Expose your local dev environment to Twilio with ngrok

expose-your-local-dev-environment-to-twilio-with-ngrok page anchor

To use the webhooks in this code sample, Twilio must communicate with your web app. These communications consist of HTTP requests sent between URLs accessible over the internet. Twilio requires access to Internet-addressable, or public, URLs.

(warning)

Protect your webhooks

Twilio supports HTTP Basic and Digest Authentication. This type of authentication protects your TwiML URLs on your web server with an Auth Token. This limits access to the URLs to you and Twilio. Protect your auth tokens as you would your passwords. To learn more, see HTTP authentication.

Create a public URL for your app

create-a-public-url-for-your-app page anchor

Most production systems have a public URL, but development systems might not. To permit Twilio to access your local dev app, use ngrok. To create a public URL for your app, run ngrok at the command line:

ngrok http 3000 --url https://<your-app-name>.ngrok.dev

This command creates a public URL https://<your-app-name>.ngrok.dev. that forwards HTTP requests to your web app listening on localhost:3000.

API output resembles the following:

Configure Twilio connection to your web app

configure-twilio-connection-to-your-web-app page anchor

With your public URL created, configure its connection to Twilio using a webhook.


After following this guide, you can retrieve single or filtered call logs using Twilio Programmable Voice in your application.


Explore the following guides to build on what you've learned in this guide: