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

Install dependencies

composer require nexmo/client
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

Prerequisites

Install dependencies

gem install nexmo
Initialize your dependencies

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

Copy to Clipboard
begin
  response = client.secrets.create(secret: 'Th1s-I5-my_n3w-s3cr3t')
  puts 'Secret Created Successfully' if response.created_at
rescue StandardError => e
  puts e.message
end

View full source

Run your code

Save this file to your machine and run it:

ruby create-a-secret.rb