Retrieve Call Logs with Java

In this guide we'll learn how to retrieve information about in progress and completed calls from your Twilio account using Java.

We’ll use Twilio’s Java SDK in these examples to interact with the Twilio REST APIs Calls endpoint.


The first thing we'll need to get started is your Twilio 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

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.getAccount().getCalls()" and iterate over it.
Loading Code Samples...
Language
SDK Version:
  • 6.x
  • 7.x
Format:
  • JSON
  • XML
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.list.CallList;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    
    
    CallList calls = client.getAccount().getCalls();
    
    // Loop over calls and print out a property for each one.
    for (Call call : calls) {
      System.out.println(call.getDirection());
    }
    
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.base.ResourceSet;
import com.twilio.rest.api.v2010.account.Call;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    ResourceSet<Call> calls = Call.reader().read();

    // Loop over calls and print out a property for each one.
    for (Call call : calls) {
      System.out.println(call.getDirection());
    }
  }
}
{
    "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:
  • 6.x
  • 7.x
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.list.CallList;
import java.util.HashMap;
import java.util.Map;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the CallList
    Map<String, String> params = new HashMap<String, String>();
    
    params.put("Status", "busy");
    params.put("To", "+15558675309");
    
    CallList calls = client.getAccount().getCalls(params);
    
    // Loop over calls and print out a property for each one.
    for (Call call : calls) {
      System.out.println(call.getStartTime());
    }
    
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.incomingphonenumber.LocalCreator;
import com.twilio.rest.api.v2010.account.availablephonenumbercountry.LocalReader;
import com.twilio.base.ResourceSet;
import com.twilio.rest.api.v2010.account.availablephonenumbercountry.Local;
import com.twilio.type.PhoneNumber;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    ResourceSet<Local> numbers = new LocalReader("US").setAreaCode(619).setContains("555").read();
    PhoneNumber availableNumber = numbers.iterator().next().getPhoneNumber();

    new LocalCreator(availableNumber).create();
  }
}
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:
  • 6.x
  • 7.x
Format:
  • JSON
  • XML
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Call;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Get an object from its sid. If you do not have a sid,
    // check out the list resource examples on this page
    Call call = client.getAccount().getCall("CA42ed11f93dc08b952027ffbc406d0868");
    System.out.println(call.getTo());
    
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Call;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    // Get an object from its sid. If you do not have a sid,
    // check out the list resource examples on this page
    Call call = Call.fetcher("CA42ed11f93dc08b952027ffbc406d0868").fetch();

    System.out.println(call.getTo());
  }
}
{
	"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 Java. Check out our tutorials to see full implementations of Twilio Voice in Java.

David Prothero
Ricky Robinett
Andrew Baker
Rob Spectre
Agustin Camino
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:
  • 6.x
  • 7.x
Format:
  • JSON
  • XML
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.list.CallList;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    
    
    CallList calls = client.getAccount().getCalls();
    
    // Loop over calls and print out a property for each one.
    for (Call call : calls) {
      System.out.println(call.getDirection());
    }
    
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.base.ResourceSet;
import com.twilio.rest.api.v2010.account.Call;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    ResourceSet<Call> calls = Call.reader().read();

    // Loop over calls and print out a property for each one.
    for (Call call : calls) {
      System.out.println(call.getDirection());
    }
  }
}
{
    "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:
  • 6.x
  • 7.x
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.list.CallList;
import java.util.HashMap;
import java.util.Map;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the CallList
    Map<String, String> params = new HashMap<String, String>();
    
    params.put("Status", "busy");
    params.put("To", "+15558675309");
    
    CallList calls = client.getAccount().getCalls(params);
    
    // Loop over calls and print out a property for each one.
    for (Call call : calls) {
      System.out.println(call.getStartTime());
    }
    
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.incomingphonenumber.LocalCreator;
import com.twilio.rest.api.v2010.account.availablephonenumbercountry.LocalReader;
import com.twilio.base.ResourceSet;
import com.twilio.rest.api.v2010.account.availablephonenumbercountry.Local;
import com.twilio.type.PhoneNumber;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    ResourceSet<Local> numbers = new LocalReader("US").setAreaCode(619).setContains("555").read();
    PhoneNumber availableNumber = numbers.iterator().next().getPhoneNumber();

    new LocalCreator(availableNumber).create();
  }
}
SDK Version:
  • 6.x
  • 7.x
Format:
  • JSON
  • XML
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Call;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Get an object from its sid. If you do not have a sid,
    // check out the list resource examples on this page
    Call call = client.getAccount().getCall("CA42ed11f93dc08b952027ffbc406d0868");
    System.out.println(call.getTo());
    
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Call;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    // Get an object from its sid. If you do not have a sid,
    // check out the list resource examples on this page
    Call call = Call.fetcher("CA42ed11f93dc08b952027ffbc406d0868").fetch();

    System.out.println(call.getTo());
  }
}
{
	"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>