Delete a User

In this code snippet you learn how to delete a User.

Example

Ensure the following variables are set to your required values using any convenient method:

KeyDescription
USER_ID

The unique ID of the User.

Prerequisites

You will need to use an existing Application and have a User in order to be able to delete a User. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.

Write the code

Add the following to delete-user.sh:

curl -X "DELETE" "https://api.nexmo.com/v1/users/$USER_ID" \
     -H 'Authorization: Bearer '$JWT\
     -H 'Content-Type: application/json'

View full source

Run your code

Save this file to your machine and run it:

bash delete-user.sh

Prerequisites

You will need to use an existing Application and have a User in order to be able to delete a User. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.
npm install @vonage/server-sdk

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

const { Vonage } = require('@vonage/server-sdk');

const vonage = new Vonage({
  applicationId: VONAGE_APPLICATION_ID,
  privateKey: VONAGE_PRIVATE_KEY,
});

View full source

Write the code

Add the following to delete-user.js:

vonage.users.deleteUser(USER_ID)
  .then(() => console.log('User deleted'))
  .catch((error) => console.error(error));

View full source

Run your code

Save this file to your machine and run it:

node delete-user.js

Prerequisites

You will need to use an existing Application and have a User in order to be able to delete a User. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.

Add the following to build.gradle:

implementation 'com.vonage:server-sdk-kotlin:2.1.1'

Create a file named DeleteUser and add the following code to the main method:

val client = Vonage {
    applicationId(VONAGE_APPLICATION_ID)
    privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
}

View full source

Write the code

Add the following to the main method of the DeleteUser file:

client.users.user(USER_ID).delete()

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.vonage.quickstart.kt.users with the package containing DeleteUser:

gradle run -Pmain=com.vonage.quickstart.kt.users.DeleteUser

Prerequisites

You will need to use an existing Application and have a User in order to be able to delete a User. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.

Add the following to build.gradle:

implementation 'com.vonage:server-sdk:9.3.1'

Create a file named DeleteUser and add the following code to the main method:

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 DeleteUser file:

client.getUsersClient().deleteUser(USER_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.vonage.quickstart.users with the package containing DeleteUser:

gradle run -Pmain=com.vonage.quickstart.users.DeleteUser

Prerequisites

You will need to use an existing Application and have a User in order to be able to delete a User. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.
Install-Package Vonage

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

using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Vonage;
using Vonage.Request;
using Vonage.Users.DeleteUser;

View full source

Add the following to DeleteUser.cs:

var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(credentials);

View full source

Write the code

Add the following to DeleteUser.cs:

var response = await client.UsersClient.DeleteUserAsync(DeleteUserRequest.Parse(USER_ID));

View full source

Prerequisites

You will need to use an existing Application and have a User in order to be able to delete a User. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.
pip install vonage python-dotenv

Write the code

Add the following to delete-user.py:

from vonage import Auth, Vonage

client = Vonage(
    Auth(
        application_id=VONAGE_APPLICATION_ID,
        private_key=VONAGE_PRIVATE_KEY,
    )
)
client.users.delete_user(USER_ID)

View full source

Run your code

Save this file to your machine and run it:

python users/delete-user.py

Try it out

When you run the code you will delete the specified User.