Create a secret

To create a new API secret, you must send a POST request to the secret management API.

New API secrets must meet the following rules:

Write the code

Add the following to create-secret.sh:

Copy to Clipboard
curl -X POST "https://api.nexmo.com/accounts/$ACCOUNT_ID/secrets" \
     -H 'Content-Type: application/json' \
     -u "$NEXMO_API_KEY:$NEXMO_API_SECRET" \
     -d '{"secret":"Th1s-I5-my_n3w-s3cr3t"}'

View full source

Run your code

Save this file to your machine and run it:

$ bash create-secret.sh

Prerequisites

Initialize your dependencies

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

Copy to Clipboard
$secret = 'awes0meNewSekret!!;';

$client->account()->createSecret(NEXMO_API_KEY, $secret);

View full source

Run your code

Save this file to your machine and run it:

$ php create-a-secret.php