Look up a number with Java
You can quickly see how the Number Lookup API works by looking up a number using the API.
What you need to know before you start
Before you can get started, you need the following already set up:
- Set all Number Lookup 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:
gradle init
app
, and then accept the defaults for the rest of the options.Modify your application
Open theApp.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.
Fill in your parameters
Before you can run the code, you need to update some more values so you can connect to your Sinch account. Update the following parameters with your own values:
Parameter | Your value |
---|---|
key | The key found on your Sinch dashboard. |
secret | The secret found on your Sinch dashboard. |
number | The phone number that you want to look up in E.164 format. |
Save the file.
Look up your phone number
Now you can execute the code and look up your phone number. Run the following command:
gradle run
You should receive a response in your console with details about the phone number you specified.
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.