Retrieve information for all calls

A code snippet 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 VONAGE_APPLICATION_ID and private key that were used to create the calls.

Generate your JWT

Execute the following command at your terminal prompt to create the JWT for authentication:

export JWT=$(nexmo jwt:generate $PATH_TO_PRIVATE_KEY application_id=$NEXMO_APPLICATION_ID)

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 VONAGE_APPLICATION_ID and private key that were used to create the calls.

Install dependencies

npm install @vonage/server-sdk
Initialize your dependencies

Create a file named get-calls.js and add the following code:

Copy to Clipboard
const Vonage = require('@vonage/server-sdk');

const vonage = new Vonage({
  apiKey: VONAGE_API_KEY,
  apiSecret: VONAGE_API_SECRET,
  applicationId: VONAGE_APPLICATION_ID,
  privateKey: VONAGE_PRIVATE_KEY
}, {debug: true});

View full source

Write the code

Add the following to get-calls.js:

Copy to Clipboard
vonage.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 get-calls.js

Prerequisites

Use your existing application

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

Install dependencies

Add the following to `build.gradle`:

compile 'com.vonage:client:5.5.0'
Initialize your dependencies

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

Copy to Clipboard
VonageClient client = VonageClient.builder()
        .applicationId(VONAGE_APPLICATION_ID)
        .privateKeyPath(VONAGE_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 = CallsFilter.builder()
            .dateStart(getYesterdaysDate())
            .dateEnd(getTodaysDate())
            .build();

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

    // com.fasterxml.jackson.databind.ObjectMapper;
    System.out.println(new ObjectMapper().writer().writeValueAsString(calls));
}

private static Date getTodaysDate() {
    return Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime();
}

private static Date getYesterdaysDate() {
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.DATE, -1);
    return calendar.getTime();
}

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.vonage.quickstart.voice with the package containing RetrieveInfoForAllCalls:

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

Prerequisites

Use your existing application

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

Install dependencies

Install-Package Nexmo.Csharp.Client
Import dependencies

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

Copy to Clipboard
using Vonage;
using Vonage.Request;
using Vonage.Voice;

View full source

Initialize your dependencies

Add the following to ListAllCalls.cs:

Copy to Clipboard
var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(credentials);

View full source

Write the code

Add the following to ListAllCalls.cs:

Copy to Clipboard
var DATE_END = DateTime.UtcNow;
var DATE_START = DATE_END.AddDays(-1);
var request = new CallSearchFilter() { DateStart = DATE_START, DateEnd = DATE_END};

View full source

Prerequisites

Use your existing application

To fetch information about your calls, you must use the same VONAGE_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 \Vonage\Client\Credentials\Keypair(
    file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
    VONAGE_APPLICATION_ID
);

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

View full source

Write the code

Add the following to index.php:

Copy to Clipboard
$filter = new \Vonage\Voice\Filter\VoiceFilter();
$filter->setDateStart(new DateTime('-1 Day'));
$filter->setDateEnd(new DateTime());

/** @var \Vonage\Voice\Call $call */
foreach ($client->voice()->search($filter) as $call) {
    echo json_encode($call->toArray()) . 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 VONAGE_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 vonage, os
from pprint import pprint
from datetime import datetime, timedelta
from os.path import join, dirname
from dotenv import load_dotenv

dotenv_path = join(dirname(__file__), "../.env")
load_dotenv(dotenv_path)

View full source

Write the code

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

Copy to Clipboard
VONAGE_APPLICATION_ID = os.environ.get("VONAGE_APPLICATION_ID")
VONAGE_APPLICATION_PRIVATE_KEY_PATH = os.environ.get("VONAGE_APPLICATION_PRIVATE_KEY_PATH")

voice = vonage.Voice(
    application_id=VONAGE_APPLICATION_ID,
    private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
)

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 VONAGE_APPLICATION_ID and private key that were used to create the calls.

Install dependencies

gem install vonage
Initialize your dependencies

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

Copy to Clipboard
client = Vonage::Client.new(
  application_id: VONAGE_APPLICATION_ID,
  private_key: File.read(VONAGE_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.voice.list({date_start: yesterday.utc.iso8601, date_end: now.utc.iso8601})

calls = response._embedded.voice
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.