You can quickly see how the Number Lookup API works by looking up a number using the API.
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.
To quickly get started setting up a simple client application using the Java SDK:
- If you haven't already, clone the sinch-sdk-java repository.
- Navigate to the
examples/snippets/src/main/resourcesfolder. - Open the
config.propertiesfile. Using the access key credentials from your Sinch Build Dashboard, populate the following fields with your values:
| Field | Description |
|---|---|
| SINCH_PROJECT_ID | The unique ID of your Project. |
| SINCH_KEY_ID | The unique ID of your access key. |
| SINCH_KEY_SECRET | The secret that goes with your access key. Note: For security reasons, this secret is only visible right after access key creation. |
This tutorial uses basic authentication for testing purposes. We recommend using OAuth for authentication in a production environment. You can follow the steps in this guide, but use the code samples from here to use OAuth authentication instead.
Save the file.
Navigate to the
examples/snippets/src/main/java/numberlookupfolder and open theLookup.javafile.
// Use this code to look up a phone number using the Number Lookup API.
/**
* Sinch Java Snippet
*
* <p>This snippet is available at https://github.com/sinch/sinch-sdk-java
*
* <p>See https://github.com/sinch/sinch-sdk-java/blob/main/examples/snippets/README.md for details
*/
package numberlookup;
import com.sinch.sdk.SinchClient;
import com.sinch.sdk.domains.numberlookup.api.v2.NumberLookupV2Service;
import com.sinch.sdk.domains.numberlookup.models.v2.request.LookupFeatureType;
import com.sinch.sdk.domains.numberlookup.models.v2.request.NumberLookupRequest;
import com.sinch.sdk.domains.numberlookup.models.v2.response.NumberLookupResponse;
import com.sinch.sdk.models.Configuration;
import java.util.Collections;
import java.util.logging.Logger;
import utils.Settings;
public class Lookup {
private static final Logger LOGGER = Logger.getLogger(Lookup.class.getName());
public static void main(String[] args) {
String projectId = Settings.getProjectId().orElse("MY_PROJECT_ID");
String keyId = Settings.getKeyId().orElse("MY_KEY_ID");
String keySecret = Settings.getKeySecret().orElse("MY_KEY_SECRET");
// The phone number you want to lookup in E.164 format
String phoneNumber = "PHONE_NUMBER";
Configuration configuration =
Configuration.builder()
.setProjectId(projectId)
.setKeyId(keyId)
.setKeySecret(keySecret)
.build();
SinchClient client = new SinchClient(configuration);
NumberLookupV2Service numberLookupService = client.lookup().v2();
NumberLookupRequest request =
NumberLookupRequest.builder()
.setNumber(phoneNumber)
.setFeatures(Collections.singletonList(LookupFeatureType.LINE_TYPE))
.build();
LOGGER.info("Lookup for: " + phoneNumber);
NumberLookupResponse response = numberLookupService.lookup(request);
LOGGER.info("Response: " + response);
}
}Before you can run the code, you need to update the following parameters with your own values:
Parameter Your value numberThe phone number that you want to look up in E.164 format. Save the file.
Now you can execute the code and look up your phone number. Open a terminal to the examples/snippets folder and run the following command:
launcher numberlookup/LookupYou should receive a response in your console with details about the phone number you specified.
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.



