Skip to main content
Version: Java

Your First Verification

This guide will help you get started with the Number Verify API by going through the steps to perform your first verification.

Prerequisites

Before you begin, you need to have the following:

Step 1: Get your API Credentials

To get your API Credentials, you can go to the Number Verify Product Page and click on "Manage on Provider" to access the service dashboard. For a full guide on how to get your credentials, you can refer to the Registration guide.

Step 2: Create a new project

Create a new folder and enter the folder from a terminal.

mkdir number-verify-test
cd number-verify-test

Step 3: Initialize the application

gradle init --type java-application

Step 4: Add the Glide SDK Dependency

Open the build.gradle file and add the Glide SDK dependency inside the dependencies block:

dependencies {
// Other dependencies
implementation("com.fasterxml.jackson.core:jackson-databind:2.15.2")
implementation("com.fasterxml.jackson.core:jackson-core:2.15.2")

// Glide SDK
implementation("com.glideapi:glide-sdk-java:1.0.2")
}
info

make sure to sync the project after adding the dependency or run the following command:

./gradlew build

Step 5: Perform a Verification

App.java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.glideapi.GlideClient;
import com.glideapi.services.NumberVerifyClient;

public class App {

public static String PHONE_NUMBER = "+555123456789";
public static ObjectMapper objectMapper = new ObjectMapper();

public static void main(String[] args) throws Exception {
GlideClient glideClient = new GlideClient(<GLIDE_CLIENT_ID>, <GLIDE_CLIENT_SECRET>);
NumberVerifyClient.NumberVerifyAuthUrlInput urlInput = new NumberVerifyClient.NumberVerifyAuthUrlInput(PHONE_NUMBER, true);
String authUrl = glideClient.numberVerify.getAuthUrl(urlInput);

HttpClient client = HttpClient.newBuilder()
.followRedirects(HttpClient.Redirect.ALWAYS)
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(authUrl))
.GET()
.build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
JsonNode jsonNode = objectMapper.readTree(response.body());
String code = jsonNode.get("code").asText();

NumberVerifyClient.NumberVerifyClientForParams params = new NumberVerifyClient.NumberVerifyClientForParams(code, PHONE_NUMBER);
NumberVerifyClient.NumberVerifyUserClient userClient = glideClient.numberVerify.forUser(params);

NumberVerifyClient.NumberVerifyResponse verifyResponse = userClient.verifyNumber(null, null);
System.out.println("number verify response - verified: " + verifyResponse.devicePhoneNumberVerified);
}
}

The code starts by generating an authentication URL to be used by the user's device to identify the device. printCode is used to print the code for testing instead of the auth server redirecting to the registered callback URL.

The code then fetches the URL and extracts the code from the response. This code is then used to create a user client to verify the phone number. The verification response is then logged to the console.

info

Since we are using the test number +555123456789, the authentication url can be simply fetched from the script instead of running from the user's device.

To execute this you can run the following from your IDE or you can use the following command:

./gradlew run

Next Steps

Congratulations! You have successfully performed your first verification using the Number Verify API. Next, you can follow our 5-minute quickstart to deploying a test application using the Number Verify API.