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
NEXMO_SECRET_ID The ID of the secret to delete.

Write the code

Add the following to revoke-secret.sh:

Copy to Clipboard
curl -X DELETE "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 revoke-secret.sh

Prerequisites

Install dependencies

npm install nexmo
Initialize your dependencies

Create a file named delete-secret.js and add the following code:

Copy to Clipboard
const Nexmo = require('nexmo')

const nexmo = new Nexmo({
  apiKey: NEXMO_API_KEY,
  apiSecret: NEXMO_API_SECRET
})

View full source

Write the code

Add the following to delete-secret.js:

Copy to Clipboard
nexmo.account.deleteSecret(NEXMO_API_KEY, NEXMO_SECRET_ID, (err, result) => {
    if (err) {
        console.log("Error: " + err.statusCode);
        console.log(err.body);
    } else {
        console.log("Secret deleted");
    }
});

View full source

Run your code

Save this file to your machine and run it:

node delete-secret.js

Prerequisites

Install dependencies

Add the following to build.gradle:

compile 'com.nexmo:client:5.1.0'
Initialize your dependencies

Create a class named RevokeSecret and add the following code to the main method:

Copy to Clipboard
NexmoClient client = NexmoClient.builder()
        .apiKey(NEXMO_API_KEY)
        .apiSecret(NEXMO_API_SECRET)
        .build();

View full source

Write the code

Add the following to the main method of the RevokeSecret class:

Copy to Clipboard
AccountClient accountClient = client.getAccountClient();

accountClient.revokeSecret(NEXMO_API_KEY, NEXMO_SECRET_ID);

View full source

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.nexmo.quickstart.account with the package containing RevokeSecret:

gradle run -Pmain=com.nexmo.quickstart.account.RevokeSecret

Prerequisites

Install dependencies

Install-Package Nexmo.Csharp.Client
Initialize your dependencies

Create a file named AccountController.cs and add the following code:

Copy to Clipboard
const string API_KEY = "NEXMO_API_KEY";
const string API_SECRET = "NEXMO_API_SECRET";

var client = new Client(creds: new Nexmo.Api.Request.Credentials(
    nexmoApiKey: API_KEY, nexmoApiSecret: API_SECRET));

View full source

Write the code

Add the following to AccountController.cs:

Copy to Clipboard
var result = Client.ApiSecret.Delete(NEXMO_API_KEY, NEXMO_SECRET_ID);

if (result )
{
    ViewBag.deleteResult = "Secret deleted";
}

View full source

Prerequisites

Install dependencies

composer require nexmo/client
Initialize your dependencies

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

Copy to Clipboard
try {
    $response = $client->account()->deleteSecret(NEXMO_API_KEY, NEXMO_SECRET_ID);
    echo "OK\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 delete-a-secret.php

Prerequisites

Install dependencies

gem install nexmo
Initialize your dependencies

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

Copy to Clipboard
begin
  response = client.secrets.revoke(NEXMO_SECRET_ID)
  puts 'OK' if response == :no_content
rescue StandardError => e
  puts e.message
end

View full source

Run your code

Save this file to your machine and run it:

ruby revoke-a-secret.rb