Retrieve information for all calls

A building block that shows how to retrieve information for all calls.

Example

Prerequisites

Use your existing application

To fetch information about your calls, you must use the same NEXMO_APPLICATION_ID and private key that were used to create the calls.

Write the code

Add the following to retrieve-info-for-all-calls.sh:

Copy to Clipboard
curl "https://api.nexmo.com/v1/calls" \
  -H "Authorization: Bearer "$JWT \

View full source 

Run your code

Save this file to your machine and run it:

$ bash retrieve-info-for-all-calls.sh

Prerequisites

Use your existing application

To fetch information about your calls, you must use the same NEXMO_APPLICATION_ID and private key that were used to create the calls.

Install dependencies

$ npm install nexmo dotenv
Initialize your dependencies

Create a file named app.js and add the following code:

Copy to Clipboard
const Nexmo = require('nexmo');

const nexmo = new Nexmo({
  apiKey: NEXMO_API_KEY,
  apiSecret: NEXMO_API_SECRET,
  applicationId: NEXMO_APPLICATION_ID,
  privateKey: NEXMO_PRIVATE_KEY
}, {debug: true});

View full source 

Write the code

Add the following to app.js:

Copy to Clipboard
nexmo.calls.get({}, (err, res) => {
  if(err) { console.error(err); }
  else {
    res._embedded.calls.forEach((call) => {
      console.log(call);
    });
  }
});

View full source 

Run your code

Save this file to your machine and run it:

$ node app.js

Prerequisites

Use your existing application

To fetch information about your calls, you must use the same NEXMO_APPLICATION_ID and private key that were used to create the calls.

Install dependencies

Add the following to build.gradle:

compile 'com.nexmo:client:4.0.0'
Initialize your dependencies

Create a class named RetrieveInfoForAllCalls and add the following code to the main method:

Copy to Clipboard
NexmoClient client = new NexmoClient.Builder()
        .applicationId(NEXMO_APPLICATION_ID)
        .privateKeyPath(NEXMO_PRIVATE_KEY_PATH)
        .build();

View full source 

Write the code

Add the following to the main method of the RetrieveInfoForAllCalls class:

Copy to Clipboard
CallsFilter filter = new CallsFilter.Builder()
        .dateStart(getYesterdaysDate())
        .dateEnd(getTodaysDate())
        .build();

CallInfoPage calls = client.getVoiceClient().listCalls(filter);

View full source 

Run your code

We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:

apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Run the following gradle command to execute your application, replacing com.nexmo.quickstart.voice with the package containing RetrieveInfoForAllCalls:

gradle run -Pmain=com.nexmo.quickstart.voice.RetrieveInfoForAllCalls

Prerequisites

Use your existing application

To fetch information about your calls, you must use the same NEXMO_APPLICATION_ID and private key that were used to create the calls.

Install dependencies

$ Install-Package Nexmo.Csharp.Client
Initialize your dependencies

Create a file named VoiceController.cs and add the following code:

Copy to Clipboard
var client = new Client(creds: new Nexmo.Api.Request.Credentials
{
    ApiKey = "NEXMO_API_KEY",
    ApiSecret = "NEXMO_API_SECRET",
    ApplicationId = "NEXMO_APPLICATION_ID",
    ApplicationKey = "NEXMO_APPLICATION_PRIVATE_KEY"
});

View full source 

Write the code

Add the following to VoiceController.cs:

Copy to Clipboard
public ActionResult CallList()
{
    var results = Client.Call.List()._embedded.calls;

    ViewData.Add("results", results);
  
    return View();
}

View full source 

Run your code

Save this file to your machine and run it:

$ Run using your IDE

Prerequisites

Use your existing application

To fetch information about your calls, you must use the same NEXMO_APPLICATION_ID and private key that were used to create the calls.

Install dependencies

$ composer require nexmo/client
Initialize your dependencies

Create a file named index.php and add the following code:

Copy to Clipboard
$keypair = new \Nexmo\Client\Credentials\Keypair(
    file_get_contents(NEXMO_APPLICATION_PRIVATE_KEY_PATH),
    NEXMO_APPLICATION_ID
);

$client = new \Nexmo\Client($keypair);

View full source 

Write the code

Add the following to index.php:

Copy to Clipboard
$filter = new \Nexmo\Call\Filter();
$filter->setStart(new DateTime('- 1 day'));
$filter->setEnd(new DateTime);

foreach ($client->calls($filter) as $call){
    echo json_encode($call).PHP_EOL;
}

View full source 

Run your code

Save this file to your machine and run it:

$ php index.php

Prerequisites

Use your existing application

To fetch information about your calls, you must use the same NEXMO_APPLICATION_ID and private key that were used to create the calls.

Install dependencies

$ pip install nexmo
Initialize your dependencies

Create a file named retrieve-info-for-all-calls.py and add the following code:

Copy to Clipboard
import nexmo
from pprint import pprint
from datetime import datetime, timedelta

client = nexmo.Client(
    application_id=APPLICATION_ID,
    private_key=APPLICATION_PRIVATE_KEY_PATH,
)

View full source 

Write the code

Add the following to retrieve-info-for-all-calls.py:

Copy to Clipboard
NOW = datetime.utcnow()
DATE_END = NOW.replace(microsecond=0).isoformat()+"Z"
DATE_START = (NOW - timedelta(hours=24, minutes=00)).replace(microsecond=0).isoformat()+"Z"

response = client.get_calls(date_start=DATE_START, date_end=DATE_END)
calls = response['_embedded']['calls']
for call in calls:
    pprint(call)

View full source 

Run your code

Save this file to your machine and run it:

$ python3 retrieve-info-for-all-calls.py

Prerequisites

Use your existing application

To fetch information about your calls, you must use the same NEXMO_APPLICATION_ID and private key that were used to create the calls.

Install dependencies

$ gem install nexmo
Initialize your dependencies

Create a file named retrieve-info-for-all-calls.rb and add the following code:

Copy to Clipboard
require 'nexmo'
require 'time'

client = Nexmo::Client.new(
    application_id: NEXMO_APPLICATION_ID,
    private_key: File.read(NEXMO_APPLICATION_PRIVATE_KEY_PATH)
)

View full source 

Write the code

Add the following to retrieve-info-for-all-calls.rb:

Copy to Clipboard
now = Time.now
yesterday = now - (3600 * 24)

response = client.calls.list({date_start: yesterday.utc.iso8601, date_end: now.utc.iso8601})

calls = response._embedded.calls
calls.each do |call|
    puts call.inspect
end

View full source 

Run your code

Save this file to your machine and run it:

$ ruby retrieve-info-for-all-calls.rb

Try it out

Run the example code to retrieve information for all calls.