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

Write the code

Add the following to list-secrets.sh:

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

View full source

Run your code

Save this file to your machine and run it:

bash list-secrets.sh

Prerequisites

Install dependencies

npm install nexmo
Initialize your dependencies

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

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

const nexmo = new Nexmo({
  apiKey: NEXMO_API_KEY,
  apiSecret: NEXMO_API_SECRET
})

View full source

Write the code

Add the following to list-secrets.js:

Copy to Clipboard
nexmo.account.listSecrets(NEXMO_API_KEY, (err, result) => {
    if (!err) {
        let secrets = result._embedded.secrets;

        secrets.forEach((secret) => {
            console.log(secret.id, secret.created_at);
        });

    }
});

View full source

Run your code

Save this file to your machine and run it:

node list-secrets.js

Prerequisites

Install dependencies

Add the following to build.gradle:

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

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

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

ListSecretsResponse response = accountClient.listSecrets(NEXMO_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.nexmo.quickstart.account with the package containing ListSecrets:

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

Prerequisites

Install dependencies

Install-Package Nexmo.Csharp.Client
Initialize your dependencies

Create a file named AccountController.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 AccountController.cs:

Copy to Clipboard
var result = Client.ApiSecret.List(NEXMO_API_KEY);

if (result.Count > 0)
{
    ViewBag.listResults = result;
    ViewBag.count = result.Count;
}

View full source

Prerequisites

Install dependencies

composer require nexmo/client
Initialize your dependencies

Create a file named list-secrets.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($basic);

View full source

Write the code

Add the following to list-secrets.php:

Copy to Clipboard
$response = $client->account()->listSecrets(NEXMO_API_KEY);
foreach($response['secrets'] as $secret) {
    echo "ID: " . $secret['id'] . " (created " . $secret['created_at'] .")\n";
}

View full source

Run your code

Save this file to your machine and run it:

php list-secrets.php

Prerequisites

Install dependencies

gem install nexmo
Initialize your dependencies

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

Copy to Clipboard
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