# Look up a number with Java You can quickly see how the Number Lookup API works by looking up a number using the API. In this guide you will learn: 1. How to [set up](#set-up-your-java-application) your Java application. 2. [Look up](#look-up-your-phone-number) your phone number. ## 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](/docs/number-lookup-api-v2/getting-started). * [JDK 8](https://www.oracle.com/java/technologies/downloads/) or later and a familiarity with how to create a new Java application. * [Gradle](https://gradle.org/install/) 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: ```shell 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 OAuth for authentication in a production environment. You can follow the steps in this guide, but use the code samples from [here](/docs/number-lookup-api-v2/api-reference/authentication/oauth) to use OAuth authentication instead. App.java // Use this code to look up a phone number using the Number Lookup API. package app; import java.net.*; import java.net.http.*; import java.util.*; public class App { private static final String key = ""; private static final String secret = ""; private static final String projectId = ""; private static final String number = ""; public static void main(String[] args) throws Exception { var httpClient = HttpClient.newBuilder().build(); var payload = String.join("\n" , "{" , " \"number\": \"" + number + "\"," , "}" ); var host = "https://lookup.api.sinch.com/v2/projects"; var pathname = "/" + projectId + "/lookups"; var request = HttpRequest.newBuilder() .POST(HttpRequest.BodyPublishers.ofString(payload)) .uri(URI.create(host + pathname )) .header("Content-Type", "application/json") .header("Authorization", "Basic " + Base64.getEncoder().encodeToString((key + ":" + secret).getBytes())) .build(); var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } ### 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 access key found on your Sinch [Build dashboard](https://dashboard.sinch.com/settings/access-keys). | | `secret` | The access secret found on your Sinch [Build dashboard](https://dashboard.sinch.com/settings/access-keys). | | `projectId` | Your project ID found on your Sinch [Build dashboard](https://dashboard.sinch.com/settings/access-keys). | | `number` | The phone number that you want to look up in [E.164](https://community.sinch.com/t5/Glossary/E-164/ta-p/7537) 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: ```shell 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. ## Additional resources - [API specification](/docs/number-lookup-api-v2/api-reference/)