Retrieve information for a call

A code snippet that shows how to retrieve information for a call. The call to retrieve information for is identified via a UUID.

Example

Replace the following variables in the example code:

Key Description
UUID The UUID for the call for which information is being requested.

Prerequisites

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

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-a-call.sh:

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

View full source

Run your code

Save this file to your machine and run it:

bash retrieve-info-for-a-call.sh

Prerequisites

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

npm install @vonage/server-sdk

Create a file named get-call.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-call.js:

Copy to Clipboard
vonage.calls.get(UUID, (err, res) => {
  if(err) { console.error(err); }
  else {
      console.log(res);
  }
});

View full source

Run your code

Save this file to your machine and run it:

node get-call.js

Prerequisites

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

Add the following to `build.gradle`:

compile 'com.vonage:client:5.5.0'

Create a class named RetrieveCallInfo 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 RetrieveCallInfo class:

Copy to Clipboard
/*
Establish a call for testing purposes.
 */
CallEvent call = client.getVoiceClient().createCall(new Call(
        TO_NUMBER,
        VONAGE_NUMBER,
        "https://nexmo-community.github.io/ncco-examples/long-tts.json"
));

/*
Give them time to answer.
 */
Thread.sleep(10000);

final String UUID = call.getUuid();
System.out.println(client.getVoiceClient().getCallDetails(UUID));

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:

Copy to Clipboard
  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 RetrieveCallInfo:

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

Prerequisites

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

Install-Package Vonage

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

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

View full source

Add the following to RetrieveInfoForCall.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 RetrieveInfoForCall.cs:

Copy to Clipboard
var response = client.VoiceClient.GetCall(UUID);

View full source

Prerequisites

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

composer require vonage/client

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
$call = $client->voice()->get(VONAGE_CALL_UUID);
echo json_encode($call->toArray());

View full source

Run your code

Save this file to your machine and run it:

php index.php

Prerequisites

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

pip install vonage

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

Copy to Clipboard
voice = Voice(
    Client(
        application_id=VONAGE_APPLICATION_ID,
        private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
    )
)

View full source

Write the code

Add the following to retrieve-info-for-a-call.py:

Copy to Clipboard
response = voice.get_call(VONAGE_CALL_UUID)
pprint(response)

View full source

Run your code

Save this file to your machine and run it:

python3 retrieve-info-for-a-call.py

Prerequisites

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

gem install vonage

Create a file named retrieve-info-for-a-call.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-a-call.rb:

Copy to Clipboard

response = client.voice.get(UUID)

View full source

Run your code

Save this file to your machine and run it:

ruby retrieve-info-for-a-call.rb

Try it out

You will need to:

  1. Set up a call and obtain the call UUID. You could use the 'connect an inbound call' code snippet to do this.
  2. Retrieve information for the call (this code snippet).