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

Search for a Verify Request

You can use the search functionality to see the current status or eventual outcome of a Verify request, using the request_id returned when the verify code was sent.

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 search-for-verify-request.sh:

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

View full source

Run your code

Save this file to your machine and run it:

sh search-for-verify-request.sh

Prerequisites

Install dependencies

npm install nexmo
Initialize your dependencies

Create a file named search.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
});

View full source

Write the code

Add the following to search.js:

Copy to Clipboard
nexmo.verify.search(REQUEST_ID, (err, result) => {
  if (err) {
    console.error(err);
  } else {
    console.log('Request status:', result.status);
  }
});

View full source

Run your code

Save this file to your machine and run it:

node search.js

Prerequisites

Install dependencies

Add the following to build.gradle:

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

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

Copy to Clipboard
    VerifyClient verifyClient = client.getVerifyClient();

    SearchVerifyResponse response = verifyClient.search(REQUEST_ID);
    if (response.getStatus() == VerifyStatus.OK) {
        response.getVerificationRequests().forEach(it -> {
            System.out.println(it.getRequestId() + " " + it.getStatus());
        });
    }
}

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 SearchVerification:

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

Prerequisites

Install dependencies

Install-Package Nexmo.Csharp.Client
Initialize your dependencies

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

Copy to Clipboard
const string API_KEY = "NEXMO_API_KEY";
const string API_SECRET = "NEXMO_API_SECRET";

var client = new Client(creds: new Nexmo.Api.Request.Credentials(
    nexmoApiKey: API_KEY, nexmoApiSecret: API_SECRET));

View full source

Write the code

Add the following to VerifySender.cs:

Copy to Clipboard
var result = client.NumberVerify.Search(new NumberVerify.SearchRequest
{
    request_id = REQUEST_ID
});

View full source

Prerequisites

Install dependencies

gem install nexmo
Initialize your dependencies

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

Copy to Clipboard
response = client.verify.search(request_id: REQUEST_ID)

if !response.error_text
  # The current status of this request, for example:
  # => IN PROGRESS
  puts response.status
else
  puts response.error_text
end

View full source

Run your code

Save this file to your machine and run it:

ruby search.rb