Revoke a secret
To create a new API secret, you must send a DELETE
request to the secret management API.
You must have at least one API secret at all times.
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). |
ACCOUNT_ID |
The account ID to target |
VONAGE_SECRET_ID |
The ID of the secret to delete. |
Write the code
Add the following to revoke-secret.sh
:
curl -X DELETE "https://api.nexmo.com/accounts/$ACCOUNT_ID/secrets/$SECRET_ID" \
-u "$VONAGE_API_KEY:$VONAGE_API_SECRET"
Run your code
Save this file to your machine and run it:
bash revoke-secret.sh
Prerequisites
npm install @vonage/server-sdk
Create a file named delete-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 delete-secret.js
:
vonage.account.deleteSecret(VONAGE_API_KEY, VONAGE_SECRET_ID, (err, result) => {
if (err) {
console.log("Error: " + err.statusCode);
console.log(err.body);
} else {
console.log("Secret deleted");
}
});
Run your code
Save this file to your machine and run it:
node delete-secret.js
Prerequisites
Add the following to `build.gradle`:
compile 'com.vonage:client:5.5.0'
Create a class named RevokeSecret
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 RevokeSecret
class:
AccountClient accountClient = client.getAccountClient();
accountClient.revokeSecret(VONAGE_API_KEY, VONAGE_SECRET_ID);
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 RevokeSecret
:
gradle run -Pmain=com.vonage.quickstart.account.RevokeSecret
Prerequisites
Install-Package Vonage
Create a file named RevokeSecret.cs
and add the following code:
using Vonage.Accounts;
using Vonage;
using Vonage.Request;
Add the following to RevokeSecret.cs
:
var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(credentials);
Write the code
Add the following to RevokeSecret.cs
:
var response = client.AccountClient.RevokeApiSecret(VONAGE_SECRET_ID, VONAGE_API_KEY);
Prerequisites
composer require vonage/client
Create a file named delete-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 delete-a-secret.php
:
try {
$response = $client->account()->deleteSecret(VONAGE_API_KEY, VONAGE_SECRET_ID);
echo "OK\n";
} catch(\Vonage\Client\Exception\Request $e) {
echo $e->getMessage();
}
Run your code
Save this file to your machine and run it:
php delete-a-secret.php
Prerequisites
pip install vonage
Create a file named revoke-secret.py
and add the following code:
client = vonage.Client(
key=os.getenv("VONAGE_API_KEY"), secret=os.getenv("VONAGE_API_SECRET")
)
Write the code
Add the following to revoke-secret.py
:
try:
# Get the data from standard input
api_key = os.getenv("VONAGE_API_KEY")
secret_id = os.getenv("VONAGE_SECRET_ID")
client.delete_secret(api_key, secret_id)
print("Secret removed")
except:
print("Error when try to removing secret")
Run your code
Save this file to your machine and run it:
python3 revoke-secret.py
Prerequisites
gem install vonage
Create a file named revoke-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 revoke-a-secret.rb
:
begin
response = client.secrets.revoke(VONAGE_SECRET_ID)
puts 'OK' if response == :no_content
rescue StandardError => e
puts e.message
end
Run your code
Save this file to your machine and run it:
ruby revoke-a-secret.rb