Excluir um usuário

Neste trecho de código, você aprenderá como excluir um usuário.

Exemplo

Certifique-se de que as seguintes variáveis estejam definidas com os valores desejados, utilizando qualquer método conveniente:

ChaveDescrição
USER_ID

The unique ID of the User.

Pré-requisitos

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.

Escreva o código

Adicione o seguinte ao arquivo ` delete-user.sh`:

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

Ver código-fonte completo

Execute seu código

Salve este arquivo no seu computador e execute-o:

bash delete-user.sh

Pré-requisitos

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

Crie um arquivo chamado ` delete-user.js ` e insira o seguinte código:

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

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

Ver código-fonte completo

Escreva o código

Adicione o seguinte ao arquivo ` delete-user.js`:

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

Ver código-fonte completo

Execute seu código

Salve este arquivo no seu computador e execute-o:

node delete-user.js

Pré-requisitos

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.

Adicione o seguinte ao arquivo ` build.gradle`:

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

Crie um arquivo chamado ` DeleteUser ` e adicione o código a seguir ao método ` main `:

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

Ver código-fonte completo

Escreva o código

Adicione o seguinte ao método ` main ` do arquivo ` DeleteUser `:

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

Ver código-fonte completo

Execute seu código

Podemos usar o plugin “ aplicativo ” para o Gradle a fim de simplificar a execução do nosso aplicativo. Atualize seu arquivo ` build.gradle ` com o seguinte:

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

Execute o seguinte comando ` gradle ` para rodar seu aplicativo, substituindo ` com.vonage.quickstart.kt.users ` pelo pacote que contém ` DeleteUser`:

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

Pré-requisitos

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.

Adicione o seguinte ao arquivo ` build.gradle`:

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

Crie um arquivo chamado ` DeleteUser ` e adicione o código a seguir ao método ` main `:

VonageClient client = VonageClient.builder()
        .apiKey(VONAGE_API_KEY)
        .apiSecret(VONAGE_API_SECRET)
        .build();

Ver código-fonte completo

Escreva o código

Adicione o seguinte ao método ` main ` do arquivo ` DeleteUser `:

client.getUsersClient().deleteUser(USER_ID);

Ver código-fonte completo

Execute seu código

Podemos usar o plugin “ aplicativo ” para o Gradle a fim de simplificar a execução do nosso aplicativo. Atualize seu arquivo ` build.gradle ` com o seguinte:

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

Execute o seguinte comando ` gradle ` para rodar seu aplicativo, substituindo ` com.vonage.quickstart.users ` pelo pacote que contém ` DeleteUser`:

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

Pré-requisitos

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

Crie um arquivo chamado ` DeleteUser.cs ` e insira o seguinte código:

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

Ver código-fonte completo

Adicione o seguinte ao arquivo ` DeleteUser.cs`:

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

Ver código-fonte completo

Escreva o código

Adicione o seguinte ao arquivo ` DeleteUser.cs`:

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

Ver código-fonte completo

Pré-requisitos

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

Escreva o código

Adicione o seguinte ao arquivo ` 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)

Ver código-fonte completo

Execute seu código

Salve este arquivo no seu computador e execute-o:

python users/delete-user.py

Experimente

Ao executar o código, você excluirá o usuário especificado.