Fetch a secret

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

KeyDescription
VONAGE_API_KEY

Your Vonage API key (see it on your dashboard).

VONAGE_API_SECRET

Your Vonage API secret (also available on your dashboard).

ACCOUNT_ID

The account ID to target

VONAGE_SECRET_ID

The ID of the secret to retrieve.

Write the code

Add the following to get-secret.sh:

curl "https://api.nexmo.com/accounts/$ACCOUNT_ID/secrets/$ACCOUNT_SECRET_ID" \
    -u "$VONAGE_API_KEY:$VONAGE_API_SECRET"

View full source

Run your code

Save this file to your machine and run it:

bash get-secret.sh

Prerequisites

npm install @vonage/server-sdk

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

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 get-api-secret.js:

vonage.secrets.getSecret(ACCOUNT_ID, ACCOUNT_SECRET_ID)
  .then((resp) => console.log(resp))
  .catch((error) => console.error(error));

View full source

Run your code

Save this file to your machine and run it:

node get-api-secret.js

Prerequisites

Add the following to build.gradle:

implementation 'com.vonage:server-sdk-kotlin:2.1.1'

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

val client = Vonage {
    apiKey(VONAGE_API_KEY)
    apiSecret(VONAGE_API_SECRET)
}

View full source

Write the code

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

val secret = client.account.secrets(ACCOUNT_ID).get(ACCOUNT_SECRET_ID)
println("ID: ${secret.id} created on: ${secret.created}")

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

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

Prerequisites

Add the following to build.gradle:

implementation 'com.vonage:server-sdk:9.3.1'

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

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

SecretResponse response = client.getAccountClient().getSecret(ACCOUNT_ID, ACCOUNT_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-Package Vonage

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

using Vonage;
using Vonage.Request;

View full source

Add the following to FetchSecret.cs:

var client = new VonageClient(credentials);

View full source

Write the code

Add the following to FetchSecret.cs:

View full source

Prerequisites

composer require vonage/client

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

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

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

pip install vonage python-dotenv

Write the code

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

from vonage import Auth, Vonage
from vonage_account import VonageApiSecret

client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET))

secret: VonageApiSecret = client.account.get_secret(ACCOUNT_SECRET_ID)

print(f'Secret ID: {secret.id}; Created at {secret.created_at}')

View full source

Run your code

Save this file to your machine and run it:

python account/fetch-a-secret.py

Prerequisites

gem install vonage

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

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:

response = client.secrets.get(ACCOUNT_SECRET_ID)

View full source

Run your code

Save this file to your machine and run it:

ruby fetch-a-secret.rb