Initiate a Phone Call verification request with Java

You can quickly see how the Verification API works by sending yourself a Phone Call verification request.

What you need to know before you start

Before you can get started, you need the following already set up:

  • Set all Verification API configuration settings.
  • JDK 8 or later and a familiarity with how to create a new Java application.
  • Gradle and a familiarity with how use the Gradle build tools.

Set up your Java application

Create a new folder where you want to keep your app project. Then, open a terminal or command prompt to that location.

Create a new Java application using Gradle with the following command:

Copy
Copied
gradle init
In the prompts, select that you want to create an application, name your project and source package app, and then accept the defaults for the rest of the options.

Modify your application

Open the App.java file in your project folder, located in \app\scr\main\java\app, and populate that file with the "App.java" code found on this page.
Note:

This tutorial uses basic authentication for testing purposes. We recommend using a signed request for authentication in a production environment. You can follow the steps in this guide, but use the code samples from here to use request signing authentication instead.

This code makes a POST request to the Verification API /verifications endpoint which sends a Phone Call verification request out to the toNumber parameter in the body of the request.

Fill in your parameters

Before you can run the code, you need to update some values so you can connect to your Sinch account. Update the following parameters with your own values:

ParameterYour value
applicationKeyThe application key found on your Sinch dashboard.
applicationSecretThe application secret found on your Sinch dashboard.
toNumberThis should be the number of the mobile handset you are using for this guide.

Save the file.

Initiate your verification request

Now you can execute the code and initiate your verification request. Run the following command:

Copy
Copied
gradle run

You should receive a phone call to your mobile handset with a text-to-speech message with your verification code. In a production scenario, this is the code that a user would enter into your app to verify their account.

Troubleshooting tip

If after running your app you receive a 5000 error response, you may have forgotten to save your file after adding your authentication values. This is an easy mistake to make! Try saving the file and running the app again.

Next steps

Now it's time to take the code you just received and use it to verify the identity of the user by reporting the code.

Additional resources

Learn more about the Verification API:

We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.