Join us in San Francisco on the 29/30th of October for two days of developer workshops and technical talks

Delete an Application

In this code snippet you will see how to delete the specified Application.

Example

You will need to ensure that the following replaceable values are set in the example code using any convenient method:

Key Description
NEXMO_API_KEY Your Nexmo API key.
NEXMO_API_SECRET Your Nexmo API secret.
NEXMO_APPLICATION_ID The application ID for the Nexmo application you want to delete.

Write the code

Add the following to delete-application.sh:

Copy to Clipboard
curl -X "DELETE" "https://api.nexmo.com/v2/applications/$NEXMO_APPLICATION_ID" \
     -H 'Content-Type: application/json' \
     -u "$NEXMO_API_KEY:$NEXMO_API_SECRET"

View full source

Run your code

Save this file to your machine and run it:

./delete-application.sh

Prerequisites

Install dependencies

npm install nexmo@beta
Initialize your dependencies

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

Copy to Clipboard
const Nexmo = require('nexmo')
   
var nexmo = new Nexmo({
    apiKey: NEXMO_API_KEY,
    apiSecret: NEXMO_API_SECRET
}, {
    debug: true
});

View full source

Write the code

Add the following to delete-application.js:

Copy to Clipboard
nexmo.applications.delete(NEXMO_APPLICATION_ID, (error, result) => {
  if(error) {
    console.error(error);
  }
  else {
    console.log(result);
  }
});

View full source

Run your code

Save this file to your machine and run it:

node delete-application.js

Prerequisites

Install dependencies

Add the following to build.gradle:

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

Create a class named DeleteApplication 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 DeleteApplication class:

Copy to Clipboard
ApplicationClient applicationClient = client.getApplicationClient();

applicationClient.deleteApplication(NEXMO_APPLICATION_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.application with the package containing DeleteApplication:

gradle run -Pmain=com.nexmo.quickstart.application.DeleteApplication

Prerequisites

Install dependencies

Install-Package Nexmo.Csharp.Client
Initialize your dependencies

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

Copy to Clipboard
var client = new Client(creds: new Nexmo.Api.Request.Credentials
{
    ApiKey = "NEXMO_API_KEY",
    ApiSecret = "NEXMO_API_SECRET"
});

View full source

Write the code

Add the following to ApplicationController.cs:

Copy to Clipboard
var result = Client.ApplicationV2.Delete(APPLICATION_ID);
if (result)
    ViewBag.deleteResult = "App deleted";

View full source

Prerequisites

Install dependencies

composer require nexmo/client
Initialize your dependencies

Create a file named delete-application.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(new \Nexmo\Client\Credentials\Container($basic));

View full source

Write the code

Add the following to delete-application.php:

Copy to Clipboard
try {
    $isDeleted = $client->applications()->delete(MESSAGES_APPLICATION_ID);

    if ($isDeleted) {
        echo "Deleted application " . MESSAGES_APPLICATION_ID . PHP_EOL;
    } else {
        echo "Could not delete application " . MESSAGES_APPLICATION_ID . PHP_EOL;
    }
} catch (\Nexmo\Client\Exception\Request $e) {
    echo "There was a problem with the request: " . $e->getMessage() . PHP_EOL;
} catch (\Nexmo\Client\Exception\Server $e) {
    echo "The server encounted an error: " . $e->getMessage() . PHP_EOL;
}

View full source

Run your code

Save this file to your machine and run it:

php delete-application.php

Prerequisites

Install dependencies

pip install nexmo
Initialize your dependencies

Create a file named delete-application.py and add the following code:

Copy to Clipboard
client = nexmo.Client(
    key=NEXMO_API_KEY,
    secret=NEXMO_API_SECRET
)

View full source

Write the code

Add the following to delete-application.py:

Copy to Clipboard
response = client.application_v2.delete_application(NEXMO_APPLICATION_ID)

pprint(response)

View full source

Run your code

Save this file to your machine and run it:

python3 delete-application.py

Prerequisites

Install dependencies

gem install nexmo
Initialize your dependencies

Create a file named delete-application.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 delete-application.rb:

Copy to Clipboard
begin
  response = client.applications_v2.delete(NEXMO_APPLICATION_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 delete-application.rb