Get an Application

In this code snippet you will see how to retrieve details of the specified Application.

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.
NEXMO_APPLICATION_ID The application ID for the Nexmo application you want to get.

Write the code

Add the following to get-application.sh:

Copy to Clipboard
curl -X "GET" "https://api.nexmo.com/v2/applications/$NEXMO_APPLICATION_ID" \
     -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:

./get-application.sh

Prerequisites

Install dependencies

npm install nexmo
Initialize your dependencies

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

Copy to Clipboard
nexmo.applications.get(NEXMO_APPLICATION_ID, (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-application.js

Prerequisites

Install dependencies

Add the following to build.gradle:

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

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

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

Application application = applicationClient.getApplication(NEXMO_APPLICATION_ID);

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 GetApplication:

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

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.Get(appId: NEXMO_APPLICATION_ID);

View full source

Prerequisites

Install dependencies

composer require nexmo/client
Initialize your dependencies

Create a file named get-application.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 get-application.php:

Copy to Clipboard
try {
    $application = $client->applications()->get(MESSAGES_APPLICATION_ID);

    echo $application->getId() . PHP_EOL;
    echo $application->getName() . PHP_EOL;
} catch (\Nexmo\Client\Exception\Request $e) {
    echo "There was a problem with the request: " . $e->getMessage() . PHP_EOL;
} catch (\Nexmo\Client\Exception\Server $e) {
    echo "The server encounted an error: " . $e->getMessage() . PHP_EOL;
}

View full source

Run your code

Save this file to your machine and run it:

php get-application.php

Prerequisites

Install dependencies

pip install nexmo
Initialize your dependencies

Create a file named get-application.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 get-application.py:

Copy to Clipboard
response = client.application_v2.get_application(NEXMO_APPLICATION_ID)

pprint(response)

View full source

Run your code

Save this file to your machine and run it:

python3 get-application.py

Prerequisites

Install dependencies

gem install nexmo
Initialize your dependencies

Create a file named get-application.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 get-application.rb:

Copy to Clipboard
begin
  response = client.applications_v2.get(NEXMO_APPLICATION_ID)
  puts "#{response.name}: #{response.id}"
rescue StandardError => e
  puts e.message
end

View full source

Run your code

Save this file to your machine and run it:

ruby get-application.rb