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
VONAGE_API_KEY Your Vonage API key.
VONAGE_API_SECRET Your Vonage API secret.
VONAGE_APPLICATION_ID The application ID for the Vonage 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/$VONAGE_APPLICATION_ID" \
     -H 'Content-Type: application/json' \
     -u "$VONAGE_API_KEY:$VONAGE_API_SECRET"

View full source

Run your code

Save this file to your machine and run it:

./delete-application.sh

Prerequisites

npm install @vonage/server-sdk

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

Copy to Clipboard
const Vonage = require('@vonage/server-sdk')
   
const vonage = new Vonage({
    apiKey: VONAGE_API_KEY,
    apiSecret: VONAGE_API_SECRET
}, {
    debug: true
});

View full source

Write the code

Add the following to delete-application.js:

Copy to Clipboard
vonage.applications.delete(VONAGE_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

Add the following to `build.gradle`:

compile 'com.vonage:client:5.5.0'

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

Copy to Clipboard
VonageClient client = VonageClient.builder()
        .apiKey(VONAGE_API_KEY)
        .apiSecret(VONAGE_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(VONAGE_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:

Copy to Clipboard
  apply plugin: 'application'
  mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Run the following gradle command to execute your application, replacing com.vonage.quickstart.application with the package containing DeleteApplication:

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

Prerequisites

Install-Package Vonage

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

Copy to Clipboard
using Vonage;
using Vonage.Request;

View full source

Add the following to DeleteApplication.cs:

Copy to Clipboard
var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(credentials);

View full source

Write the code

Add the following to DeleteApplication.cs:

Copy to Clipboard
var response = client.ApplicationClient.DeleteApplication(VONAGE_APPLICATION_ID);

View full source

Prerequisites

composer require vonage/client

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

Copy to Clipboard
$basic  = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client(new \Vonage\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(VONAGE_APPLICATION_ID);

    if ($isDeleted) {
        echo "Deleted application " . VONAGE_APPLICATION_ID . PHP_EOL;
    } else {
        echo "Could not delete application " . VONAGE_APPLICATION_ID . PHP_EOL;
    }
} catch (\Vonage\Client\Exception\Request $e) {
    echo "There was a problem with the request: " . $e->getMessage() . PHP_EOL;
} catch (\Vonage\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

pip install vonage

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

Copy to Clipboard
client = vonage.Client(
    key=VONAGE_API_KEY,
    secret=VONAGE_API_SECRET
)

View full source

Write the code

Add the following to delete-application.py:

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

View full source

Run your code

Save this file to your machine and run it:

python3 delete-application.py

Prerequisites

gem install vonage

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

Copy to Clipboard
client = Vonage::Client.new(
  api_key: VONAGE_API_KEY,
  api_secret: VONAGE_API_SECRET
)

View full source

Write the code

Add the following to delete-application.rb:

Copy to Clipboard
begin
  response = client.applications.delete(VONAGE_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