Retrieve information for all calls

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

Example

Prerequisites

Use your existing application

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

Install dependencies

Initialize your dependencies

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

Install dependencies

Initialize your dependencies

Write the code

Add the following to RetrieveInfoForAllCalls.java:

Copy to Clipboard
CallsFilter filter = new CallsFilter();
filter.setDateStart(getYesterdaysDate());
filter.setDateEnd(getTodaysDate());

CallInfoPage calls = nexmo.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 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

Install dependencies

Initialize your dependencies

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

Install dependencies

Initialize your dependencies

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

Install dependencies

Initialize your dependencies

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

Install dependencies

Initialize your dependencies

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.