Retrieve Call Logs with Node.js

In this guide we’ll show you how to how to retrieve information about in progress and completed calls from your Twilio account. The code snippets in this guide are written using modern JavaScript language features in Node.js version 6 or higher and make use of the Twilio Node.js SDK.

Let's get started!

The first thing we will need are your account credentials.

Retrieve your Twilio account credentials

First, you'll need to get your Twilio account credentials. They consist of your AccountSid and your Auth Token. They can be found on the home page of the console.

Retrieve Your Twilio Credentials

With our account credentials, we can us the Twilio Node.js module to retrieve Twilio call logs.

Retrieving call logs

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.

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

Loading Code Samples...
Language
SDK Version:
  • 2.x
  • 3.x
Format:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.calls.list(function(err, data) {
    data.calls.forEach(function(call) {
        console.log(call.Direction);
    });
});
// Download the Node helper library from twilio.com/docs/node/install
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls
  .each((call) => console.log(call.direction));
{
    "page": 0,
    "page_size": 50,
    "uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls.json?PageSize=1",
    "first_page_uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls.json?PageSize=50&Page=0",
    "previous_page_uri": null,
    "next_page_uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls.json?PageSize=50&Page=1&AfterSid=CA8d67bfc16f4b472a5b7c7bbf3c7977ae",
    "calls": [{
        "sid": "CA4c22bfc16f4b484d8b7cbe0f3c79bcc7",
        "date_created": "Tue, 12 Jun 2012 03:25:49 +0000",
        "date_updated": "Tue, 12 Jun 2012 03:27:05 +0000",
        "parent_call_sid": null,
        "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
        "to": "+18085553279",
        "to_formatted": "(808) 555-3279",
        "from": "+17075559463",
        "from_formatted": "(707) 555-9463",
        "phone_number_sid": "PN907a2531e2d34c94b24b2794e73681de",
        "status": "completed",
        "start_time": "Tue, 12 Jun 2012 03:26:15 +0000",
        "end_time": "Tue, 12 Jun 2012 03:27:05 +0000",
        "duration": "50",
        "price": "-0.02000",
        "direction": "outbound-api",
        "answered_by": null,
        "api_version": "2010-04-01",
        "forwarded_from": null,
        "caller_name": null,
        "uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7.json",
        "subresource_uris": {
            "notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7\/Notifications.json",
            "recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7\/Recordings.json"
        }
    }, ... ]
}
<TwilioResponse>
	<Calls page="0" pagesize="1" 
	uri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.xml?PageSize=50" 
	firstpageuri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.xml?PageSize=50&amp;Page=0" 
	previouspageuri="" 
	nextpageuri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.xml?PageSize=50&amp;Page=1&amp;AfterSid=CA8d67bfc16f4b472a5b7c7bbf3c7977ae">
		<Call>
			<Sid>CA4c22bfc16f4b484d8b7cbe0f3c79bcc7</Sid>
			<DateCreated>Tue, 12 Jun 2012 03:25:49 +0000</DateCreated>
			<DateUpdated>Tue, 12 Jun 2012 03:27:05 +0000</DateUpdated>
			<ParentCallSid/>
			<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
			<To>+18085553279</To>
			<ToFormatted>(808) 555-3279</ToFormatted>
			<From>+17075559463</From>
			<FromFormatted>(707) 555-9463</FromFormatted>
			<PhoneNumberSid>PN907a2531e2d34c94b24b2794e73681de</PhoneNumberSid>
			<Status>completed</Status>
			<StartTime>Tue, 12 Jun 2012 03:26:15 +0000</StartTime>
			<EndTime>Tue, 12 Jun 2012 03:27:05 +0000</EndTime>
			<Duration>50</Duration>
			<Price>-0.02000</Price>
			<Direction>outbound-api</Direction>
			<AnsweredBy/>
			<ApiVersion>2010-04-01</ApiVersion>
			<ForwardedFrom/>
			<CallerName/>
			<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7.xml</Uri>
			<SubresourceUris>
				<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7/Notifications.xml</Notifications>
				<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7/Recordings.xml</Recordings>
			</SubresourceUris>
		</Call>
		...
	</Calls>
</TwilioResponse>
List All Calls Example

You can also filter the 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.

Loading Code Samples...
Language
SDK Version:
  • 2.x
  • 3.x
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls.list(
  {
    status: 'busy',
    to: '+15558675309',
  },
  (err, data) => {
    data.calls.forEach(call => {
      console.log(call.StartTime);
    });
  }
);
// Download the Node helper library from twilio.com/docs/node/install
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

const filterOpts = {
  status: 'busy',
  to: '+15558675309',
};

client.calls.each(filterOpts, call => console.log(call.startTime));
Retrieve Busy Calls To Specific Number Example

Finally, if you just want to retrieve information about a specific call you can get that CallSid directly.

Loading Code Samples...
Language
SDK Version:
  • 2.x
  • 3.x
Format:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls('CA42ed11f93dc08b952027ffbc406d0868').get((err, call) => {
  console.log(call.to);
});
// Download the Node helper library from twilio.com/docs/node/install
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client
  .calls('CA42ed11f93dc08b952027ffbc406d0868')
  .fetch()
  .then(call => console.log(call.to));
{
	"sid": "CAe1644a7eed5088b159577c5802d8be38",
	"date_created": "Tue, 10 Aug 2010 08:02:17 +0000",
	"date_updated": "Tue, 10 Aug 2010 08:02:47 +0000",
	"parent_call_sid": null,
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"to": "+14153855708",
	"from": "+14158141819",
	"phone_number_sid": null,
	"status": "completed",
	"start_time": "Tue, 10 Aug 2010 08:02:31 +0000",
	"end_time": "Tue, 10 Aug 2010 08:02:47 +0000",
	"duration": "16",
	"price": "-0.03000",
	"direction": "outbound-api",
	"answered_by": null,
	"api_version": "2008-08-01",
	"forwarded_from": null,
	"caller_name": null,
	"uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAe1644a7eed5088b159577c5802d8be38.json",
	"subresource_uris":{
		"notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAe1644a7eed5088b159577c5802d8be38\/Notifications.json",
		"recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAe1644a7eed5088b159577c5802d8be38\/Recordings.json"
	}
}
<TwilioResponse>
	<Call>
		<Sid>CAe1644a7eed5088b159577c5802d8be38</Sid>
		<DateCreated>Tue, 10 Aug 2010 08:02:17 +0000</DateCreated>
		<DateUpdated>Tue, 10 Aug 2010 08:02:47 +0000</DateUpdated>
		<ParentCallSid/>
		<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
		<To>+14153855708</To>
		<From>+14158141819</From>
		<PhoneNumberSid></PhoneNumberSid>
		<Status>completed</Status>
		<StartTime>Tue, 10 Aug 2010 08:02:31 +0000</StartTime>
		<EndTime>Tue, 10 Aug 2010 08:02:47 +0000</EndTime>
		<Duration>16</Duration>
		<Price>-0.03000</Price>
		<Direction>outbound-api</Direction>
		<AnsweredBy/>
		<ApiVersion>2008-08-01</ApiVersion>
		<ForwardedFrom/>
		<CallerName/>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAe1644a7eed5088b159577c5802d8be38</Uri>
		<SubresourceUris>
			<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAe1644a7eed5088b159577c5802d8be38/Notifications</Notifications>
			<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAe1644a7eed5088b159577c5802d8be38/Recordings</Recordings>
		</SubresourceUris>
	</Call>
</TwilioResponse>
Retrieve Call By Id Example

Where to next?

We just learned how to retrieve Twilio call logs using JavaScript. Check out our tutorials to see full implementations of Twilio Voice in Node.js with Express.

David Prothero
Jose Oliveros
Ricky Robinett
Rob Spectre
Andrew Baker
Kevin Whinnery

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 browsing the Twilio tag on Stack Overflow.

1 / 1
Loading Code Samples...
SDK Version:
  • 2.x
  • 3.x
Format:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.calls.list(function(err, data) {
    data.calls.forEach(function(call) {
        console.log(call.Direction);
    });
});
// Download the Node helper library from twilio.com/docs/node/install
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls
  .each((call) => console.log(call.direction));
{
    "page": 0,
    "page_size": 50,
    "uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls.json?PageSize=1",
    "first_page_uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls.json?PageSize=50&Page=0",
    "previous_page_uri": null,
    "next_page_uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls.json?PageSize=50&Page=1&AfterSid=CA8d67bfc16f4b472a5b7c7bbf3c7977ae",
    "calls": [{
        "sid": "CA4c22bfc16f4b484d8b7cbe0f3c79bcc7",
        "date_created": "Tue, 12 Jun 2012 03:25:49 +0000",
        "date_updated": "Tue, 12 Jun 2012 03:27:05 +0000",
        "parent_call_sid": null,
        "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
        "to": "+18085553279",
        "to_formatted": "(808) 555-3279",
        "from": "+17075559463",
        "from_formatted": "(707) 555-9463",
        "phone_number_sid": "PN907a2531e2d34c94b24b2794e73681de",
        "status": "completed",
        "start_time": "Tue, 12 Jun 2012 03:26:15 +0000",
        "end_time": "Tue, 12 Jun 2012 03:27:05 +0000",
        "duration": "50",
        "price": "-0.02000",
        "direction": "outbound-api",
        "answered_by": null,
        "api_version": "2010-04-01",
        "forwarded_from": null,
        "caller_name": null,
        "uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7.json",
        "subresource_uris": {
            "notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7\/Notifications.json",
            "recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7\/Recordings.json"
        }
    }, ... ]
}
<TwilioResponse>
	<Calls page="0" pagesize="1" 
	uri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.xml?PageSize=50" 
	firstpageuri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.xml?PageSize=50&amp;Page=0" 
	previouspageuri="" 
	nextpageuri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.xml?PageSize=50&amp;Page=1&amp;AfterSid=CA8d67bfc16f4b472a5b7c7bbf3c7977ae">
		<Call>
			<Sid>CA4c22bfc16f4b484d8b7cbe0f3c79bcc7</Sid>
			<DateCreated>Tue, 12 Jun 2012 03:25:49 +0000</DateCreated>
			<DateUpdated>Tue, 12 Jun 2012 03:27:05 +0000</DateUpdated>
			<ParentCallSid/>
			<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
			<To>+18085553279</To>
			<ToFormatted>(808) 555-3279</ToFormatted>
			<From>+17075559463</From>
			<FromFormatted>(707) 555-9463</FromFormatted>
			<PhoneNumberSid>PN907a2531e2d34c94b24b2794e73681de</PhoneNumberSid>
			<Status>completed</Status>
			<StartTime>Tue, 12 Jun 2012 03:26:15 +0000</StartTime>
			<EndTime>Tue, 12 Jun 2012 03:27:05 +0000</EndTime>
			<Duration>50</Duration>
			<Price>-0.02000</Price>
			<Direction>outbound-api</Direction>
			<AnsweredBy/>
			<ApiVersion>2010-04-01</ApiVersion>
			<ForwardedFrom/>
			<CallerName/>
			<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7.xml</Uri>
			<SubresourceUris>
				<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7/Notifications.xml</Notifications>
				<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA4c22bfc16f4b484d8b7cbe0f3c79bcc7/Recordings.xml</Recordings>
			</SubresourceUris>
		</Call>
		...
	</Calls>
</TwilioResponse>
SDK Version:
  • 2.x
  • 3.x
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls.list(
  {
    status: 'busy',
    to: '+15558675309',
  },
  (err, data) => {
    data.calls.forEach(call => {
      console.log(call.StartTime);
    });
  }
);
// Download the Node helper library from twilio.com/docs/node/install
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

const filterOpts = {
  status: 'busy',
  to: '+15558675309',
};

client.calls.each(filterOpts, call => console.log(call.startTime));
SDK Version:
  • 2.x
  • 3.x
Format:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls('CA42ed11f93dc08b952027ffbc406d0868').get((err, call) => {
  console.log(call.to);
});
// Download the Node helper library from twilio.com/docs/node/install
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client
  .calls('CA42ed11f93dc08b952027ffbc406d0868')
  .fetch()
  .then(call => console.log(call.to));
{
	"sid": "CAe1644a7eed5088b159577c5802d8be38",
	"date_created": "Tue, 10 Aug 2010 08:02:17 +0000",
	"date_updated": "Tue, 10 Aug 2010 08:02:47 +0000",
	"parent_call_sid": null,
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"to": "+14153855708",
	"from": "+14158141819",
	"phone_number_sid": null,
	"status": "completed",
	"start_time": "Tue, 10 Aug 2010 08:02:31 +0000",
	"end_time": "Tue, 10 Aug 2010 08:02:47 +0000",
	"duration": "16",
	"price": "-0.03000",
	"direction": "outbound-api",
	"answered_by": null,
	"api_version": "2008-08-01",
	"forwarded_from": null,
	"caller_name": null,
	"uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAe1644a7eed5088b159577c5802d8be38.json",
	"subresource_uris":{
		"notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAe1644a7eed5088b159577c5802d8be38\/Notifications.json",
		"recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAe1644a7eed5088b159577c5802d8be38\/Recordings.json"
	}
}
<TwilioResponse>
	<Call>
		<Sid>CAe1644a7eed5088b159577c5802d8be38</Sid>
		<DateCreated>Tue, 10 Aug 2010 08:02:17 +0000</DateCreated>
		<DateUpdated>Tue, 10 Aug 2010 08:02:47 +0000</DateUpdated>
		<ParentCallSid/>
		<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
		<To>+14153855708</To>
		<From>+14158141819</From>
		<PhoneNumberSid></PhoneNumberSid>
		<Status>completed</Status>
		<StartTime>Tue, 10 Aug 2010 08:02:31 +0000</StartTime>
		<EndTime>Tue, 10 Aug 2010 08:02:47 +0000</EndTime>
		<Duration>16</Duration>
		<Price>-0.03000</Price>
		<Direction>outbound-api</Direction>
		<AnsweredBy/>
		<ApiVersion>2008-08-01</ApiVersion>
		<ForwardedFrom/>
		<CallerName/>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAe1644a7eed5088b159577c5802d8be38</Uri>
		<SubresourceUris>
			<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAe1644a7eed5088b159577c5802d8be38/Notifications</Notifications>
			<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAe1644a7eed5088b159577c5802d8be38/Recordings</Recordings>
		</SubresourceUris>
	</Call>
</TwilioResponse>