# Search for a virtual number using .NET SDK Use this guide to create a .NET application for use with the Numbers API and search for an available Sinch virtual number. Note: Before you can get started, you need the following already set up: - - [.NET 7.0 SDK](https://dotnet.microsoft.com/download) or later and a familiarity with how to create a new app. Steps: 1. [Set up](#set-up-your-net-application) your .NET application. 2. [Search for an available virtual number](#search-for-an-available-virtual-number) for SMS, Voice or both. # Sinch .NET SDK for Numbers API The Sinch Numbers .NET SDK allows you to quickly interact with the Numbers API from inside your .NET applications. ## Set up your .NET application 1. Create a new folder where you want your app project. Then, open a terminal or command prompt to that location. 2. Create a new .NET console app with the following command: ```shell dotnet new console ``` The easiest way to install the SDK is using the [`dotnet` CLI](https://learn.microsoft.com/en-us/dotnet/core/install/windows?tabs=net70): 1. Open a command prompt or terminal to the local repository folder. 2. Execute the following command: ```shell dotnet add package Sinch ``` 1. Open the `Program.cs` file in your project folder. Replace all of the code with the "Search for a virtual number" code. Program.cs // Use this code to search for available virtual numbers with the .NET SDK. using System.Text.Json; using Sinch; using Sinch.Numbers; using Sinch.Numbers.Available.List; var sinch = new SinchClient("YOUR_project_id", "YOUR_access_key", "YOUR_access_secret"); var response = await sinch.Numbers.Available.List(new ListAvailableNumbersRequest { RegionCode = "US", Type = Types.Local }); Console.WriteLine(JsonSerializer.Serialize(response, new JsonSerializerOptions() { WriteIndented = true })); ### Modify your application The code provided includes placeholder parameters. You'll need to update the parameters detailed in the following subsections with your values. #### Initialize the client Before initializing a client using this SDK, you'll need three pieces of information: - Your Project ID - An access key ID - An access key Secret These values can be found on the [Access Keys](https://dashboard.sinch.com/settings/access-keys) page of the Sinch Build Dashboard. You can also [create new access key IDs and Secrets](https://community.sinch.com/t5/Conversation-API/How-to-get-your-access-key-for-Conversation-API/ta-p/8120), if required. Note If you have trouble accessing the above link, ensure that you have gained access to the [Conversation API](https://dashboard.sinch.com/convapi/overview) by accepting the corresponding terms and conditions. To start using the SDK, you need to initialize the main client class with your credentials from your Sinch [dashboard](https://dashboard.sinch.com). Note: For testing purposes on your local environment it's fine to use hardcoded values, but before deploying to production we strongly recommend using environment variables to store the credentials. ```cpp Initialize client using Sinch; var sinch = new SinchClient("YOUR_project_id", "YOUR_access_key", "YOUR_access_secret"); ``` You can also implement the client using ASP.NET dependency injection. `SinchClient` is thread safe, so it's fine to add it as a singleton: ```cpp Initialize client using dependency injection builder.Services.AddSingleton(x => new SinchClient( builder.Configuration["YOUR_project_id"], builder.Configuration["YOUR_access_key"], builder.Configuration["YOUR_access_secret"])); ``` When finished, save the file. ### Build your project Before executing your code, you must first compile your application. Execute the following command: ```shell dotnet build ``` ## Search for an available number Now you can execute the code. Run the following command: ```shell dotnet run ``` ### Response These steps should return a JSON list of numbers available to rent. ```json { "availableNumbers": [ { "phoneNumber": "+12089087284", "regionCode": "US", "type": "LOCAL", "capability": ["SMS"], "setupPrice": { "currencyCode": "USD", "amount": "0.00" }, "monthlyPrice": { "currencyCode": "USD", "amount": "2.00" }, "paymentIntervalMonths": 1 } ] } ``` ## Next steps Copy the `phoneNumber` you would like to use and [rent your virtual number using the Numbers API](/docs/numbers/getting-started/dotnet-sdk/rentandconfig). ## Additional resources - Explore the [API specification](/docs/numbers/api-reference/numbers) to test more endpoints. - Prefer a UI to search for a number? Follow the entire number searching and renting process [in the Sinch Build Dashboard](https://dashboard.sinch.com/numbers/buy-numbers).