# Look up a number with .NET 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-net-application) your ASP.NET Core console 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/api-reference). * [.NET 7.0](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) or later SDK and .NET Runtime and a familiarity with how to create an app. ## Set up your .NET application Create a new project folder and open a command prompt. Execute the following command to create a new .NET console application: ```shell dotnet new console ``` This creates a new console application and project. ## Modify your application In your project folder, open the Program.cs file and paste the provided "Program.cs" code into the file, replacing all the existing content. 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. Program.cs // Use this code to look up a phone number using the Number Lookup API. using System.Text; using System.Text.Json; using static System.Net.Mime.MediaTypeNames; class Program { private const string _number = ""; /* An access key and secret and the project ID from your Build dashboard, found here https://dashboard.sinch.com/settings/access-keys */ private const string _key = ""; private const string _secret = ""; private const string _project_id = ""; private const string _sinchUrl = "https://lookup.api.sinch.com/v2/projects/" + _project_id + "/lookups"; static async Task Main(string[] args) { await LookupNumberWithBasicAuth(); } private static async Task LookupNumberWithBasicAuth() { using (var _client = new HttpClient()) { var requestBody = LookupNumberRequestBody(); var base64String = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{_key}:{_secret}")); var requestMessage = new HttpRequestMessage(HttpMethod.Post, _sinchUrl); requestMessage.Headers.TryAddWithoutValidation("authorization", "basic " + base64String); requestMessage.Content = requestBody; var request = await _client.SendAsync(requestMessage); Console.WriteLine(await request.Content.ReadAsStringAsync()); request.EnsureSuccessStatusCode(); } } public static StringContent LookupNumberRequestBody() { var myData = new { number = _number }; return new StringContent( JsonSerializer.Serialize(myData), Encoding.UTF8, Application.Json ); } } ### 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). | | `_project_id` | 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. ## Build your project Before executing your code, you must first compile your application. Execute the following command: ```shell dotnet build ``` ## Look up your phone number Now you can execute the code and look up your phone number. Run the following command: ```shell dotnet 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/)