Fetch a secret

This will return the details of a single secret. The value of the secret will never be shown.

Key Description
VONAGE_API_KEY The API key of the account to fetch secrets for. Can be the same as authenticating account or it can be a subaccount.
VONAGE_SECRET_ID The ID of the secret to retrieve.

Write the code

Add the following to get-secret.sh:

Copy to Clipboard
curl "https://api.nexmo.com/accounts/$ACCOUNT_ID/secrets/$SECRET_ID" \
    -u "$NEXMO_API_KEY:$NEXMO_API_SECRET"

View full source

Run your code

Save this file to your machine and run it:

bash get-secret.sh

Prerequisites

Install dependencies

npm install @vonage/server-sdk
Initialize your dependencies

Create a file named fetch-a-secret.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
})

View full source

Write the code

Add the following to fetch-a-secret.js:

Copy to Clipboard
vonage.account.getSecret(VONAGE_API_KEY, VONAGE_SECRET_ID, (err, result) => {
    if (!err) {
        console.log(result.id, result.created_at);
    }
});

View full source

Run your code

Save this file to your machine and run it:

node fetch-a-secret.js

Prerequisites

Install dependencies

Add the following to `build.gradle`:

compile 'com.vonage:client:5.5.0'
Initialize your dependencies

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

Copy to Clipboard
VonageClient client = VonageClient.builder()
        .apiKey(VONAGE_API_KEY)
        .apiSecret(VONAGE_API_SECRET)
        .build();

View full source

Write the code

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

Copy to Clipboard
AccountClient accountClient = client.getAccountClient();

SecretResponse response = accountClient.getSecret(VONAGE_API_KEY, VONAGE_SECRET_ID);
System.out.println(response.getId() + " created at " + response.getCreated());

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.vonage.quickstart.account with the package containing GetSecret:

gradle run -Pmain=com.vonage.quickstart.account.GetSecret

Prerequisites

Install dependencies

Install-Package Nexmo.Csharp.Client
Import dependencies

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

Copy to Clipboard
using Vonage;
using Vonage.Request;

View full source

Initialize your dependencies

Add the following to FetchSecret.cs:

Copy to Clipboard
var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(credentials);

View full source

Write the code

Add the following to FetchSecret.cs:

Copy to Clipboard
var response = client.AccountClient.RetrieveApiSecret(VONAGE_SECRET_ID, VONAGE_API_KEY);

View full source

Prerequisites

Install dependencies

composer require vonage/client
Initialize your dependencies

Create a file named fetch-a-secret.php and add the following code:

Copy to Clipboard
$basic  = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

View full source

Write the code

Add the following to fetch-a-secret.php:

Copy to Clipboard
try {
    $secret = $client->account()->getSecret(VONAGE_API_KEY, VONAGE_SECRET_ID);
    echo "ID: " . $secret->getId() . " (created " . $secret->getCreatedAt() .")\n";
} catch (\Vonage\Client\Exception\Request $e) {
    echo $e->getMessage();
}

View full source

Run your code

Save this file to your machine and run it:

php fetch-a-secret.php

Prerequisites

Install dependencies

gem install vonage
Initialize your dependencies

Create a file named fetch-a-secret.rb and add the following code:

Copy to Clipboard
client = Vonage::Client.new(
  api_key: VONAGE_API_KEY,
  api_secret: VONAGE_API_SECRET
)

View full source

Write the code

Add the following to fetch-a-secret.rb:

Copy to Clipboard
result = client.secrets.get(VONAGE_SECRET_ID)

puts "ID: #{result.id} created on #{result.created_at}"

View full source

Run your code

Save this file to your machine and run it:

ruby fetch-a-secret.rb