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:
- Minimum 8 characters
- Maximum 25 characters
- Minimum 1 lower case character
- Minimum 1 upper case character
- Minimum 1 digit
| 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). |
NEW_SECRET | The new API secret for the API key. |
Write the code
Add the following to create-secret.sh:
curl -X POST "https://api.nexmo.com/accounts/$ACCOUNT_ID/secrets" \
-H 'Content-Type: application/json' \
-u "$VONAGE_API_KEY:$VONAGE_API_SECRET" \
-d '{"secret":"Th1s-I5-my_n3w-s3cr3t"}'Run your code
Save this file to your machine and run it:
Prerequisites
npm install @vonage/server-sdkCreate a file named create-secret.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET,
});Write the code
Add the following to create-secret.js:
vonage.secrets.createSecret(VONAGE_API_KEY, NEW_SECRET)
.then((resp) => console.log(resp))
.catch((resp) => console.error(resp.response.data));Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk-kotlin:1.1.2'Create a file named CreateSecret and add the following code to the main method:
val client = Vonage {
apiKey(VONAGE_API_KEY)
apiSecret(VONAGE_API_SECRET)
}Write the code
Add the following to the main method of the CreateSecret file:
val secret = client.account.secrets().create(NEW_SECRET)
println("ID: ${secret.id} created on: ${secret.created}")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.kt.account with the package containing CreateSecret:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:8.15.1'Create a file named CreateSecret and add the following code to the main method:
VonageClient client = VonageClient.builder()
.apiKey(VONAGE_API_KEY)
.apiSecret(VONAGE_API_SECRET)
.build();Write the code
Add the following to the main method of the CreateSecret file:
SecretResponse response = client.getAccountClient().createSecret(VONAGE_API_KEY, NEW_SECRET);
System.out.println(response.getId() + " created at " + response.getCreated());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 CreateSecret:
Prerequisites
Install-Package VonageCreate a file named CreateSecret.cs and add the following code:
using Vonage.Accounts;
using Vonage;
using Vonage.Request;Add the following to CreateSecret.cs:
var client = new VonageClient(credentials);
Write the code
Add the following to CreateSecret.cs:
var response = await client.AccountClient.CreateApiSecretAsync(request, apiKey);
Prerequisites
composer require vonage/clientCreate a file named create-a-secret.php and add the following code:
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);Write the code
Add the following to create-a-secret.php:
$secret = 'awes0meNewSekret!!;';
$client->account()->createSecret(VONAGE_API_KEY, $secret);Run your code
Save this file to your machine and run it:
Prerequisites
pip install vonageWrite the code
Add the following to create-secret.py:
from vonage import Auth, Vonage
from vonage_account import VonageApiSecret
client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET))
response: VonageApiSecret = client.account.create_secret(NEW_SECRET)
print(response)Run your code
Save this file to your machine and run it:
Prerequisites
gem install vonageCreate a file named create-a-secret.rb and add the following code:
client = Vonage::Client.new(
api_key: VONAGE_API_KEY,
api_secret: VONAGE_API_SECRET
)Write the code
Add the following to create-a-secret.rb:
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
endRun your code
Save this file to your machine and run it: