Sinch .NET SDK for Numbers

The Sinch Numbers .NET SDK allows you to quickly interact with the Numbers API from inside your .NET applications. The fastest way to get started with the SDK is to check out our getting started guides. There you'll find all the instructions necessary to download, install, set up, and start using the SDK.

Syntax

When using the .NET SDK, the code representing requests and queries sent to and responses received from the Numbers API are structured similarly to those that are sent and received using the Numbers API itself.

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.

The code sample on the side of this page is an example of how to use the .NET SDK to list the available numbers given a set of constraints. The code is also displayed below, along with a Numbers API call that accomplishes the same task, for reference:

REST APISDK
Copy
Copied
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);
    }
  }
}
Copy
Copied
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
    }));

This example highlights the following required to successfully make a Numbers API call using the Sinch .NET SDK:

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 successfully initialize the Sinch client class, you must provide a valid access key ID and access key secret combination. You must also provide your Project ID. For example:

Copy
Copied
using Sinch;

var sinch = new SinchClient(configuration["Sinch:ProjectId"],
                            configuration["Sinch:KeyId"], 
                            configuration["Sinch:KeySecret"]);

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()].

Endpoint categories

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:

Copy
Copied
using Sinch.Numbers.Available.List;

ListAvailableNumbersResponse numbers_available = await sinch.Numbers.Available.List(new ListAvailableNumbersRequest
{
    RegionCode = "US",
    Type = Types.Local
});

Numbers.Available endpoint category

The Numbers.Available category of the .NET SDK corresponds to the availableNumbers endpoint. The mapping between the API operations and corresponding .NET methods are described below:
API operationSDK method
Rent the first available number matching the provided criteriaRentAny()
Activate a new phone numberActivate()
Search for available phone numbersList()

Numbers.Active endpoint category

The Numbers.Active category of the .NET SDK corresponds to the activeNumbers endpoint. The mapping between the API operations and corresponding .NET methods are described below:
API operationSDK method
List active numbers for a projectList()
Update active numberUpdate()
Retrieve active numberGet()
Release active numberRelease()

Numbers.Regions endpoint category

The Numbers.Regions category of the .NET SDK corresponds to the availableRegions endpoint. The mapping between the API operations and corresponding .NET methods are described below:
API operationSDK method
List available regionsList()

Request and query parameters

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:

SDKJSON
Copy
Copied
RegionCode = "US"
Copy
Copied
"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.

Field name differences

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 nameSDK field name
regionCodeRegionCode
typeType
numberPattern.patternNumberPattern
phoneNumberPhoneNumber
smsConfigurationSmsConfiguration
capabilityCapability

Responses

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.

We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.