这份文档还在翻译中,预期年底前完成。欢迎您提供宝贵的意见及建议。
Retrieve information for all calls
A code snippet that shows how to retrieve information for all calls.
Example
Prerequisites
To fetch information about your calls, you must use the same VONAGE_APPLICATION_ID
and private key that were used to create the calls.
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
:
curl "https://api.nexmo.com/v1/calls" \
-H "Authorization: Bearer "$JWT \
Run your code
Save this file to your machine and run it:
bash retrieve-info-for-all-calls.sh
Prerequisites
To fetch information about your calls, you must use the same VONAGE_APPLICATION_ID
and private key that were used to create the calls.
npm install @vonage/server-sdk
Create a file named get-calls.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-calls.js
:
vonage.calls.get({}, (err, res) => {
if(err) { console.error(err); }
else {
res._embedded.calls.forEach((call) => {
console.log(call);
});
}
});
Run your code
Save this file to your machine and run it:
node get-calls.js
Prerequisites
To fetch information about your calls, you must use the same VONAGE_APPLICATION_ID
and private key that were used to create the calls.
Add the following to `build.gradle`:
compile 'com.vonage:client:5.5.0'
Create a class named RetrieveInfoForAllCalls
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 RetrieveInfoForAllCalls
class:
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();
}
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
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-Package Vonage
Create a file named ListAllCalls.cs
and add the following code:
using Vonage;
using Vonage.Request;
using Vonage.Voice;
Add the following to ListAllCalls.cs
:
var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(credentials);
Write the code
Add the following to ListAllCalls.cs
:
var DATE_END = DateTime.UtcNow;
var DATE_START = DATE_END.AddDays(-1);
var request = new CallSearchFilter() { DateStart = DATE_START, DateEnd = DATE_END};
Prerequisites
To fetch information about your calls, you must use the same VONAGE_APPLICATION_ID
and private key that were used to create the calls.
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
:
$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;
}
Run your code
Save this file to your machine and run it:
php index.php
Prerequisites
To fetch information about your calls, you must use the same VONAGE_APPLICATION_ID
and private key that were used to create the calls.
pip install vonage
Create a file named retrieve-info-for-all-calls.py
and add the following code:
voice = vonage.Voice(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
)
Write the code
Add the following to retrieve-info-for-all-calls.py
:
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 = voice.get_calls(date_start=DATE_START, date_end=DATE_END)
calls = response['_embedded']['calls']
for call in calls:
pprint(call)
Run your code
Save this file to your machine and run it:
python3 retrieve-info-for-all-calls.py
Prerequisites
To fetch information about your calls, you must use the same VONAGE_APPLICATION_ID
and private key that were used to create the calls.
gem install vonage
Create a file named retrieve-info-for-all-calls.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-all-calls.rb
:
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
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.