# Sinch .NET SDK for Numbers The Sinch .NET SDK allows you to quickly interact with the from inside your .NET applications. When using the .NET SDK, the code representing requests and queries sent to and responses received from the are structured similarly to those that are sent and received using the . The fastest way to get started with the SDK is to check out our [getting started](/docs/numbers/getting-started/dotnet-sdk/searchavailable) guides. There you'll find all the instructions necessary to download, install, set up, and start using the SDK. ## Syntax Note: This guide describes the syntactical structure of the .NET SDK for the Numbers API, including any differences that may exist between the API itself and the SDK. For a full reference on Numbers API calls and responses, see the [Numbers API Reference](/docs/numbers/api-reference/numbers). The code sample below is an example of how to use the .NET SDK to list the available numbers given a set of constraints. We've also provided an example that accomplishes the same task using the REST API. SDK .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 })); REST API ```cpp using System; using System.Net.Http; using System.Threading.Tasks; using System.Text; public class Program { public static async Task Main(string[] args) { using (var client = new HttpClient()) { var base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes($"YOUR_username:YOUR_password")); client.DefaultRequestHeaders.Add("Authorization", "Basic "+ base64String); var ProjectId = "YOUR_ProjectId"; var request = await client.GetAsync("https://numbers.api.sinch.com/v1/projects/" + ProjectId + "/availableNumbers?regionCode=US&type=LOCAL"); var response = await request.Content.ReadAsStringAsync(); Console.WriteLine(response); } } } ``` This example highlights the following required to successfully make a Numbers API call using the Sinch .NET SDK: - [Client initialization](#client) - [Numbers domain access](#numbers-domain) - [Endpoint usage](#endpoint-categories) - [Field population](#request-and-query-parameters) ## Client When using the Sinch .NET SDK, you initialize communication with the Sinch backend by initializing the .NET SDK's main client class. This client allows you to access the functionality of the Sinch .NET SDK. ### Initialization 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"])); ``` ## Numbers domain The Sinch .NET SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, `Sinch.Numbers.[Endpoint_Category].[Method()]`. In the Sinch .NET SDK, Numbers API endpoints are accessible through the client. The naming convention of the endpoint's representation in the SDK matches the API: - `Numbers.Available` - `Numbers.Active` - `Numbers.Regions` For example: ```cpp using Sinch.Numbers.Available.List; ListAvailableNumbersResponse numbers_available = await sinch.Numbers.Available.List(new ListAvailableNumbersRequest { RegionCode = "US", Type = Types.Local }); ``` The `Numbers.Available` category of the .NET SDK corresponds to the [availableNumbers](/docs/numbers/api-reference/numbers/available-number/) endpoint. The mapping between the API operations and corresponding .NET methods are described below: | API operation | SDK method | | --- | --- | | [Rent the first available number matching the provided criteria](/docs/numbers/api-reference/numbers/available-number/numberservice_rentanynumber) | `RentAny()` | | [Activate a new phone number](/docs/numbers/api-reference/numbers/available-number/numberservice_rentnumber) | `Activate()` | | [Search for available phone numbers](/docs/numbers/api-reference/numbers/available-number/numberservice_listavailablenumbers) | `List()` | The `Numbers.Active` category of the .NET SDK corresponds to the [activeNumbers](/docs/numbers/api-reference/numbers/active-number/) endpoint. The mapping between the API operations and corresponding .NET methods are described below: | API operation | SDK method | | --- | --- | | [List active numbers for a project](/docs/numbers/api-reference/numbers/active-number/numberservice_listactivenumbers) | `List()` | | [Update active number](/docs/numbers/api-reference/numbers/active-number/numberservice_updateactivenumber) | `Update()` | | [Retrieve active number](/docs/numbers/api-reference/numbers/active-number/numberservice_getactivenumber) | `Get()` | | [Release active number](/docs/numbers/api-reference/numbers/active-number/numberservice_releasenumber) | `Release()` | The `Numbers.Regions` category of the .NET SDK corresponds to the [availableRegions](/docs/numbers/api-reference/numbers/available-regions/) endpoint. The mapping between the API operations and corresponding .NET methods are described below: | API operation | SDK method | | --- | --- | | [List available regions](/docs/numbers/api-reference/numbers/available-regions/) | `List()` | Requests and queries made using the .NET SDK are similar to those made using the Numbers API. Many of the fields are named and structured similarly. For example, consider the representations of a Numbers API region code. One field is represented in JSON, and the other is using our .NET SDK: SDK ```cpp RegionCode = "US" ``` JSON ```json "regionCode": "US" ``` Note that the fields are nearly the same. Additionally, path parameters, request body parameters, and query parameters that are used in the API are all passed as arguments to the corresponding .NET method. When translating field names from the Numbers API to the .NET SDK, remember that many of the API field names are in **camelCase**. In the .NET SDK, field names are in **PascalCase**. This pattern change manages almost all field name translations between the API and the SDK. Below is a table detailing field names present in the Numbers API and their modified counterparts in the Numbers API .NET SDK: | API field name | SDK field name | | --- | --- | | `regionCode` | `RegionCode` | | `type` | `Type` | | `numberPattern.pattern` | `NumberPattern` | | `phoneNumber` | `PhoneNumber` | | `smsConfiguration` | `SmsConfiguration` | | `capability` | `Capability` | Response fields match the API responses. They are delivered as .NET objects. If there are any responses that differ significantly from the API responses, we note them in the endpoint category documentation.