List Applications

In this code snippet you will see how to list all v1 and v2 Applications.

Example

You will need to ensure that the following replaceable values are set in the example code using any convenient method:

Key Description
NEXMO_API_KEY Your Nexmo API key.
NEXMO_API_SECRET Your Nexmo API secret.

Write the code

Add the following to list-applications.sh:

Copy to Clipboard
curl -X "GET" "https://api.nexmo.com/v2/applications" \
     -H 'Content-Type: application/json' \
     -u "$NEXMO_API_KEY:$NEXMO_API_SECRET"

View full source

Run your code

Save this file to your machine and run it:

./list-applications.sh

Prerequisites

Install dependencies

npm install nexmo
Initialize your dependencies

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

Copy to Clipboard
const Nexmo = require('nexmo')

var nexmo = new Nexmo({
    apiKey: NEXMO_API_KEY,
    apiSecret: NEXMO_API_SECRET
}, {
    debug: true
});

View full source

Write the code

Add the following to get-applications.js:

Copy to Clipboard
nexmo.applications.get({}, (error, result) => {
  if(error) {
    console.error(error);
  }
  else {
    console.log(result);
  }
}, true);

View full source

Run your code

Save this file to your machine and run it:

node get-applications.js

Prerequisites

Install dependencies

Add the following to build.gradle:

compile 'com.nexmo:client:5.1.0'
Initialize your dependencies

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

Copy to Clipboard
NexmoClient client = NexmoClient.builder()
        .apiKey(NEXMO_API_KEY)
        .apiSecret(NEXMO_API_SECRET)
        .build();

View full source

Write the code

Add the following to the main method of the ListApplications class:

Copy to Clipboard
ApplicationClient applicationClient = client.getApplicationClient();

ApplicationList applications = applicationClient.listApplications();

applications.getApplications().forEach(
        application -> System.out.println(application.toJson())
);

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.nexmo.quickstart.application with the package containing ListApplications:

gradle run -Pmain=com.nexmo.quickstart.application.ListApplications

Prerequisites

Install dependencies

Install-Package Nexmo.Csharp.Client
Initialize your dependencies

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

Copy to Clipboard
const string API_KEY = "NEXMO_API_KEY";
const string API_SECRET = "NEXMO_API_SECRET";

var client = new Client(creds: new Nexmo.Api.Request.Credentials(
    nexmoApiKey: API_KEY, nexmoApiSecret: API_SECRET));

View full source

Write the code

Add the following to ApplicationSender.cs:

Copy to Clipboard
var response = client.ApplicationV2.List();

View full source

Prerequisites

Install dependencies

composer require nexmo/client
Initialize your dependencies

Create a file named list-applications.php and add the following code:

Copy to Clipboard
$basic  = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));

View full source

Write the code

Add the following to list-applications.php:

Copy to Clipboard
foreach ($client->applications() as $application) {
    echo sprintf("%s: %s\n", $application->getId(), $application->getName());
}

View full source

Run your code

Save this file to your machine and run it:

php list-applications.php

Prerequisites

Install dependencies

pip install nexmo
Initialize your dependencies

Create a file named list-applications.py and add the following code:

Copy to Clipboard
client = nexmo.Client(
    key=NEXMO_API_KEY,
    secret=NEXMO_API_SECRET
)

View full source

Write the code

Add the following to list-applications.py:

Copy to Clipboard
response = client.application_v2.list_applications()

pprint(response)

View full source

Run your code

Save this file to your machine and run it:

python3 list-applications.py

Prerequisites

Install dependencies

gem install nexmo
Initialize your dependencies

Create a file named list-applications.rb and add the following code:

Copy to Clipboard
client = Nexmo::Client.new(
  api_key: NEXMO_API_KEY,
  api_secret: NEXMO_API_SECRET
)

View full source

Write the code

Add the following to list-applications.rb:

Copy to Clipboard
response = client.applications_v2.list

response._embedded.applications.each do |application|
  puts "#{application.name}: #{application.id}"
end

View full source

Run your code

Save this file to your machine and run it:

ruby list-applications.rb