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 of the call leg |
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
:
curl "https://api.nexmo.com/v1/calls/"$UUID \
-H "Authorization: Bearer "$JWT \
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:
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});
Write the code
Add the following to get-call.js
:
vonage.calls.get(UUID, (err, res) => {
if(err) { console.error(err); }
else {
console.log(res);
}
});
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:
VonageClient client = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build();
Write the code
Add the following to the main
method of the RetrieveCallInfo
class:
/*
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));
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 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:
using Vonage;
using Vonage.Request;
using Vonage.Voice;
Add the following to RetrieveInfoForCall.cs
:
var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(credentials);
Write the code
Add the following to RetrieveInfoForCall.cs
:
var response = client.VoiceClient.GetCall(UUID);
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:
$keypair = new \Vonage\Client\Credentials\Keypair(
file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
VONAGE_APPLICATION_ID
);
$client = new \Vonage\Client($keypair);
Write the code
Add the following to index.php
:
$call = $client->voice()->get(VONAGE_CALL_UUID);
echo json_encode($call->toArray());
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:
voice = Voice(
Client(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
)
)
Write the code
Add the following to retrieve-info-for-a-call.py
:
response = voice.get_call(VONAGE_CALL_UUID)
pprint(response)
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:
client = Vonage::Client.new(
application_id: VONAGE_APPLICATION_ID,
private_key: File.read(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
Write the code
Add the following to retrieve-info-for-a-call.rb
:
response = client.voice.get(UUID)
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:
- Set up a call and obtain the call UUID. You could use the 'connect an inbound call' code snippet to do this.
- Retrieve information for the call (this code snippet).