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

Cancel verification request

If the user decides to cancel the verification process, you should send a control request to the Verify API. This will terminate the verification process even if the user supplied the correct code.

Replace the following variables in the sample code with your own values:

Name Description
NEXMO_API_KEY Your Nexmo API key
NEXMO_API_SECRET Your Nexmo API secret
REQUEST_ID The ID of the Verify request you wish to cancel (this is returned in the API response when you send a verification code)

Write the code

Add the following to cancel-verification-code.sh:

Copy to Clipboard
curl -X GET "https://api.nexmo.com/verify/control/json?api_key=$NEXMO_API_KEY&api_secret=$NEXMO_API_SECRET&request_id=$REQUEST_ID&cmd=cancel"

View full source

Run your code

Save this file to your machine and run it:

sh cancel-verification-code.sh

Prerequisites

Install dependencies

npm install nexmo
Initialize your dependencies

Create a file named cancel.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
}, {
  debug: true
});

View full source

Write the code

Add the following to cancel.js:

Copy to Clipboard
nexmo.verify.control({
  request_id: REQUEST_ID,
  cmd: 'cancel'
}, (err, result) => {
  if (err) {
    console.error(err);
  } else {
    console.log(result);
  }
});

View full source

Run your code

Save this file to your machine and run it:

node cancel.js

Prerequisites

Install dependencies

Add the following to build.gradle:

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

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

Copy to Clipboard
client.getVerifyClient().cancelVerification(REQUEST_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.verify with the package containing CancelVerification:

gradle run -Pmain=com.nexmo.quickstart.verify.CancelVerification

Prerequisites

Install dependencies

Install-Package Nexmo.Csharp.Client
Initialize your dependencies

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

Copy to Clipboard
public class BasicAuth
{
    public BasicAuth()
    {
        var client = new Client(creds: new Nexmo.Api.Request.Credentials

View full source

Write the code

Add the following to VerifyController.cs:

Copy to Clipboard
var results = Client.NumberVerify.Control(new NumberVerify.ControlRequest
{
    request_id = requestID,
    cmd = "cancel"
});

View full source

Prerequisites

Install dependencies

composer require nexmo/client
Initialize your dependencies

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

Copy to Clipboard
try {
    $result = $client->verify()->cancel(REQUEST_ID);
    var_dump($result->getResponseData());
}

catch(Exception $e) {
    echo 'Message: ' .$e->getMessage();
}

View full source

Run your code

Save this file to your machine and run it:

php cancel.php

Prerequisites

Install dependencies

pip install nexmo
Initialize your dependencies

Create a file named cancel.py and add the following code:

Copy to Clipboard
import nexmo

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

View full source

Write the code

Add the following to cancel.py:

Copy to Clipboard
response = client.cancel_verification(REQUEST_ID)

if response["status"] == "0":
    print("Cancellation successful")
else:
    print("Error: %s" % response["error_text"])

View full source

Run your code

Save this file to your machine and run it:

python cancel.py

Prerequisites

Install dependencies

gem install nexmo
Initialize your dependencies

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

Copy to Clipboard
response = client.verify.cancel(REQUEST_ID)

if response.status == '0'
  puts 'Verification cancelled.'
else
  puts response.error_text
end

View full source

Run your code

Save this file to your machine and run it:

ruby cancel.rb