Fetch a secret

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

Key Description
NEXMO_SECRET_ID The ID of the secret to delete.

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

Initialize your dependencies

Create a file named fetch-a-secret.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 fetch-a-secret.php:

Copy to Clipboard
try {
    $secret = $client->account()->getSecret(NEXMO_API_KEY, NEXMO_SECRET_ID);
    echo "ID: " . $secret['id'] . " (created " . $secret['created_at'] .")\n";
} catch (\Nexmo\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