List all secrets

This will return all secrets, along with their id and created_at time. The value of the secret will never be shown

Key Description
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

Write the code

Add the following to list-secrets.sh:

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

View full source

Run your code

Save this file to your machine and run it:

bash list-secrets.sh

Prerequisites

npm install @vonage/server-sdk

Create a file named list-secrets.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 list-secrets.js:

vonage.secrets.listSecrets(VONAGE_API_KEY)
    .then(resp => console.log(resp['_embedded']))
    .catch(err => console.error(err));

View full source

Run your code

Save this file to your machine and run it:

node list-secrets.js

Prerequisites

Add the following to `build.gradle`:

compile 'com.vonage:client:6.2.0'

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

AccountClient accountClient = client.getAccountClient();

ListSecretsResponse response = accountClient.listSecrets(VONAGE_API_KEY);
response.getSecrets().forEach(
        it -> System.out.println(it.getId() + " created at " + it.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 ListSecrets:

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

Prerequisites

Install-Package Vonage

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

using Vonage;
using Vonage.Request;
using System;

View full source

Add the following to ListAllSecrets.cs:


var response = await client.AccountClient.RetrieveApiSecretsAsync(apiKey);

View full source

Write the code

Add the following to ListAllSecrets.cs:

Console.WriteLine($"First Secret Response: {response.Embedded.Secrets[0].Id}");

View full source

Prerequisites

composer require vonage/client

Create a file named list-secrets.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 list-secrets.php:

$secretsCollection = $client->account()->listSecrets(VONAGE_API_KEY);
/** @var \Vonage\Account\Secret $secret */
foreach($secretsCollection->getSecrets() as $secret) {
    echo "ID: " . $secret->getId() . " (created " . $secret->getCreatedAt() .")\n";
}

View full source

Run your code

Save this file to your machine and run it:

php list-secrets.php

Prerequisites

pip install vonage

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

import os
from os.path import join, dirname
import vonage

View full source

Add the following to list-all-secrets.py:

client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)

View full source

Write the code

Add the following to list-all-secrets.py:

secrets = client.account.list_secrets(api_key=API_KEY)
for secret in secrets["_embedded"]["secrets"]:
    print(secret["id"] + ": Created on " + secret["created_at"])

View full source

Run your code

Save this file to your machine and run it:

python list-all-secrets.py

Prerequisites

gem install vonage

Create a file named list-all-secrets.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 list-all-secrets.rb:

result = client.secrets.list

result._embedded.secrets.each do |secret|
  puts "ID: #{secret.id} created on #{secret.created_at}"
end

View full source

Run your code

Save this file to your machine and run it:

ruby list-all-secrets.rb