Skip to content
Last updated

Click to view on Community.

The Sinch .NET SDK allows you to quickly interact with the suite of Sinch APIs from inside your .NET applications. When using the .NET SDK, the code representing requests and queries sent to and responses received from the suite of Sinch APIs are structured similarly to those that are sent and received using the suite of Sinch APIs.

Important .NET SDK links:

The following links are available for your reference:

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

Initialization of the .NET SDK client class can be done in two ways, depending on which product you are using.

Unified Project Authentication

To start using the SDK, you need to initialize the main client class with your credentials from your Sinch dashboard.

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.

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:

Initialize client using dependency injection
builder.Services.AddSingleton<ISinchClient>(x => new SinchClient(
    builder.Configuration["YOUR_project_id"],
    builder.Configuration["YOUR_access_key"],
    builder.Configuration["YOUR_access_secret"]));

Application Authentication

To start using the Voice API with the SDK, you need to initialize the main client class with your credentials from your Sinch dashboard and additionally create a Voice client object that uses your Voice app credentials.

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.

Initialize client
using Sinch;

var sinch = new SinchClient("YOUR_access_key", 
                            "YOUR_access_secret", 
                            "YOUR_project_id");

var voice = sinch.Voice("YOUR_application_key", "YOUR_application_secret");

Or, if you only need to use Voice API:

Initialize client for only Voice
using Sinch;

var sinch = new SinchClient(default, default, default);

var voice = sinch.Voice("YOUR_application_key", "YOUR_application_secret");

Domains

The Java SDK currently supports the following products:

Numbers Domain

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 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.

.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
    }));

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:

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:

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:

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:

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.

SMS Domain

Note:

This guide describes the syntactical structure of the .NET SDK for the SMS API, including any differences that may exist between the API itself and the SDK. For a full reference on SMS API calls and responses, see the SMS REST API Reference.

The code sample below of how to use the .NET SDK to send an SMS message. We've also provided an example that accomplishes the same task using the REST API.

send-message.cs
using System.Text.Json;
using Sinch;
using Sinch.SMS;

using Sinch.SMS.Batches.Send;

var sinch = new SinchClient("YOUR_project_id",
                            "YOUR_access_key", 
                            "YOUR_access_secret", 
                            // ensure you set the SMS hosting region. 
                            options => options.SmsRegion = SmsRegion.Us);

var response = await sinch.Sms.Batches.Send(new SendTextBatchRequest
{
    Body = "Hello! Thank you for using the Sinch .NET SDK to send an SMS.",
    From = "YOUR_Sinch_phone_number",
    To = new List<string>{"YOUR_recipient_phone_number"}
});

Console.WriteLine(JsonSerializer.Serialize(response, new JsonSerializerOptions()
    {
        WriteIndented = true
    }));

The Sinch .NET SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, Sinch.Sms.[Endpoint_Category].[Method()].

Endpoint categories

In the Sinch .NET SDK, SMS API endpoints are accessible through the client. The naming convention of the endpoint's representation in the SDK matches the API:

  • Sms.Batches
  • Sms.DeliveryReports
  • Sms.Groups
  • Sms.Inbounds

For example:

var response = await sinch.Sms.Batches.Send(new SendTextBatchRequest
{
    Body = "Hello! Thank you for using the Sinch .NET SDK to send an SMS.",
    From = "YOUR_Sinch_phone_number",
    To = new List<string>{"YOUR_recipient_phone_number"}
});

Sms.Batches endpoint category

The Sms.Batches category of the .NET SDK corresponds to the batches endpoint. The mapping between the API operations and corresponding .NET methods are described below:

API operationSDK method
SendSend()
List batchesList()
Dry runDryRun()
Get a batch messageGet()
Update a batch messageUpdate()
Replace a batchReplace()
Cancel a batch messageCancel()
Send delivery feedback for a messageSendDeliveryFeedback()

Sms.DeliveryReports endpoint category

The Sms.DeliveryReports category of the .NET SDK corresponds to the delivery_report and delivery_reports endpoints. The mapping between the API operations and corresponding .NET methods are described below:

Sms.Groups endpoint category

The Sms.Groups category of the .NET SDK corresponds to the groups endpoint. The mapping between the API operations and corresponding .NET methods are described below:

API operationSDK method
List groupsList()
Create a groupCreate()
Retrieve a groupGet()
Update a groupUpdate()
Replace a groupReplace()
Delete a groupDelete()
List group member phone numbersListMembers()

Sms.Inbounds endpoint category

The Sms.Inbounds category of the .NET SDK corresponds to the inbounds endpoint. The mapping between the API operations and corresponding .NET methods are described below:

API operationSDK method
List incoming messagesList()
Retrieve inbound messageGet()

Request and query parameters

Requests and queries made using the .NET SDK are similar to those made using the SMS API. Many of the fields are named and structured similarly. For example, consider the representations of an SMS API batch ID. One field is represented in JSON, and the other is using our .NET SDK:

BatchId = "{BATCH_ID}"

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.

For example, consider this example in which the Get() method of the Sms.Batches class is invoked:


smsResponse = sinchClient.Sms.Batches.Get("BATCH_ID");

When using the SMS API, service_plan_id and batch_id would be included as path parameters in the JSON payload. With the .NET SDK, the batch_id parameter is included as an argument in the Get() method.

Note:

Note that the service_plan_id path parameter does not need to be included in any requests created by the .NET SDK.

Field name differences

When translating field names from the SMS 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 giving some examples of field names present in the SMS API and their modified counterparts in the SMS API .NET SDK:

API field nameSDK field name
typeType
fromFrom
recipient_msisdnrecipientMsisdn

Additionally, some fields which require string values in the SMS API have enum values in the .NET SDK. Consider the following example:

SmsType Type = SmsType.MtText;

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.

Conversation Domain

Note:

This guide describes the syntactical structure of the .NET SDK for the Conversation API, including any differences that may exist between the API itself and the SDK. For a full reference on Conversation API calls and responses, see the Conversation REST API Reference.

The code sample below is an example of how to use the .NET SDK to send a text message on the SMS channel of a Conversation API app. We've also provided an example that accomplishes the same task using the REST API. (note that this REST API example uses Basic Authentication instead of OAuth2):

send-message.cs
using System.Text.Json;
using Sinch;
using Sinch.Conversation;
using Sinch.Conversation.Messages.Send;
using Sinch.Conversation.Messages.Message;
using Sinch.Conversation.Common;

var sinch = new SinchClient("YOUR_project_id",
    "YOUR_access_key",
    "YOUR_access_secret",
    // ensure you set the Conversation region. 
    options => options.ConversationRegion = ConversationRegion.Us);

var response = await sinch.Conversation.Messages.Send(new SendMessageRequest
{
    Message = new AppMessage(new TextMessage("Hello! Thank you for using the Sinch .NET SDK to send an SMS.")),
    AppId = "YOUR_app_id",
    Recipient = new Identified
    {
        IdentifiedBy = new IdentifiedBy
        {
            ChannelIdentities = new List<ChannelIdentity>
            {
                new ChannelIdentity
                {
                    AppId = "YOUR_app_id",
                    Identity = "RECIPIENT_number",
                    Channel = new ConversationChannel("SMS")
                }
            }
        }
    },
    ChannelProperties = new Dictionary<string, string> { { "SMS_SENDER", "YOUR_sms_sender" } }
});

Console.WriteLine(JsonSerializer.Serialize(response, new JsonSerializerOptions()
{
    WriteIndented = true
}));

The Sinch .NET SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, Sinch.Conversation.[Endpoint_Category].[Method()].

Endpoint categories

In the Sinch .NET SDK, Conversation API endpoints are accessible through the client (either a general client or a Conversation-specific client). The naming convention of the endpoint's representation in the SDK matches the API:

  • Messages
  • Apps
  • Contacts
  • Events
  • Transcoding
  • Capability
  • TemplatesV2
  • Webhooks
  • Conversations

For example:

var response = await sinch.Conversation.Messages.Send(new SendMessageRequest
{
    Message = new AppMessage(new TextMessage("Hello! Thank you for using the Sinch .NET SDK to send an SMS.")),
    AppId = "YOUR_app_id",
    Recipient = new Identified
    {
        IdentifiedBy = new IdentifiedBy
        {
            ChannelIdentities = new List<ChannelIdentity>
            {
                new ChannelIdentity
                {
                    AppId = "YOUR_app_id",
                    Identity = "RECIPIENT_number",
                    Channel = new ConversationChannel("SMS")
                }
            }
        }
    },
    ChannelProperties = new Dictionary<string, string> { { "SMS_SENDER", "YOUR_sms_sender" } }
});

Messages endpoint category

The Messages category of the .NET SDK corresponds to the messages endpoint. The mapping between the API operations and corresponding methods are described below:

Apps endpoint category

The Apps category of the .NET SDK corresponds to the apps endpoint. The mapping between the API operations and corresponding methods are described below:

Contacts endpoint category

The Contacts category of the .NET SDK corresponds to the contacts endpoint. The mapping between the API operations and corresponding methods are described below:

API operationSDK method
List contactsList or ListAuto
Create a contactCreate
Get a contactGet
Delete a contactDelete
Update a contactUpdate
Merge two contactsMerge
Get channel profileGetChannelProfile

Conversations endpoint category

The Conversations category of the .NET SDK corresponds to the conversations endpoint. The mapping between the API operations and corresponding methods are described below:

Events endpoint category

The Events category of the .NET SDK corresponds to the events endpoint. The mapping between the API operations and corresponding methods are described below:

API operationSDK method
Send an eventSend
Get an eventGet
Delete an eventDelete
List eventsList or ListAuto

Transcoding endpoint category

The Transcoding category of the .NET SDK corresponds to the messages:transcode endpoint. The mapping between the API operations and corresponding methods are described below:

API operationSDK method
Transcode a messageTranscode

Capability endpoint category

The Capability category of the .NET SDK corresponds to the capability endpoint. The mapping between the API operations and corresponding methods are described below:

API operationSDK method
Capability lookupLookup

Webhooks endpoint category

The Webhooks category of the .NET SDK corresponds to the webhooks endpoint. The mapping between the API operations and corresponding methods are described below:

TemplatesV2 endpoint category

The TemplatesV2 category of the .NET SDK corresponds to the Templates-V2 endpoint. The mapping between the API operations and corresponding methods are described below:

Request and query parameters

Requests and queries made using the .NET SDK are similar to those made using the Conversation API. Many of the fields are named and structured similarly. When translating field names from the Conversation 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. For example:

AppId = "YOUR_app_id"

Note that the fields have the same name. 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. For example, consider this example in which the get method of the message class is invoked:


var response = await sinch.Conversation.Messages.Get(
    messageId = "YOUR_message_id",
    messagesSource = "CONVERSATION_SOURCE"
    )
    

When using the Conversation API, message_id would be included as a path parameter, and messages_source would be included as a query parameter in the JSON payload. With the .NET SDK, both parameters are included as arguments in the get method.

Responses

Response fields match the API responses. They are delivered as .NET objects.

Voice Domain

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

Note

This guide describes the syntactical structure of the .NET SDK for the Voice API, including any differences that may exist between the API itself and the SDK. For a full reference on Voice API calls and responses, see the Voice API Reference.

The code sample below is an example of how to use the .NET SDK to make a Text-to-speech phone call. We've also provided an example that accomplishes the same task using the REST API.

Program.cs
using System.Text.Json;
using Sinch;
using Sinch.Voice.Callouts.Callout;

var sinch = new SinchClient("YOUR_access_key", 
                            "YOUR_access_secret", 
                            "YOUR_project_id");

var voice = sinch.Voice("YOUR_application_key", "YOUR_application_secret");

CalloutResponse response = await voice.Callouts.Tts(new TextToSpeechCalloutRequest{
    Destination = new Destination{
        Type = DestinationType.Number,
        Endpoint = "YOUR_phone_number"
    },
    Text = "This is a Text to speech callout to test the Sinch dotnet Voice SDK."
});
    
Console.WriteLine(JsonSerializer.Serialize(response, new JsonSerializerOptions()
{
    WriteIndented = true
}));

The Sinch .NET SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, Sinch.Voice.[Endpoint_Category].[Method()].

Endpoint categories

In the Sinch .NET SDK, Voice API endpoints are accessible through the client. The naming convention of the endpoint's representation in the SDK matches the API:

  • Voice.Callouts
  • Voice.Calls
  • Voice.Conferences
  • Voice.Applications

For example:

    using Sinch;
    using Sinch.Voice.Callouts.Callout;

    ...

    CalloutResponse response = await voice.Callouts.Tts(new TextToSpeechCalloutRequest{
    Destination = new Destination{
        Type = DestinationType.Number,
        Endpoint = "YOUR_phone_number"
    },
    Text = "This is a Text to speech callout to test the Sinch dotnet Voice SDK."
    });

Voice.Callouts endpoint category

The Voice.Callouts category of the .NET SDK corresponds corresponds to the callouts endpoint. The mapping between the API operations and corresponding .NET methods are described below:

Voice.Calls endpoint category

The Voice.Calls category of the .NET SDK corresponds corresponds to the calls endpoint. The mapping between the API operations and corresponding .NET methods are described below:

API operationSDK method
Update a call in progressUpdate()
Get information about a callGet()
Manage a call with callLegManageWithCallLeg()

Voice.Conferences endpoint category

The Voice.Conferences category of the .NET SDK corresponds corresponds to the conferences endpoint. The mapping between the API operations and corresponding .NET methods are described below:

Voice.Applications endpoint category

The Voice.Applications category of the .NET SDK corresponds corresponds to the configuration endpoint. The mapping between the API operations and corresponding .NET methods are described below:

Request and query parameters

Requests and queries made using the .NET SDK are similar to those made using the Voice API. Many of the fields are named and structured similarly. For example, consider a request to check on the status of a verification request by using the Identity of the request. One request is using the REST API, and the other is using our .NET SDK:

    var response = await voice.calls.Get(CallId);
    var request = await client.GetAsync("https://calling.api.sinch.com/calling/v1/calls/id/" + CallId);

Note that the path 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 Voice 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.

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.

Verification Domain

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

Note:

This guide describes the syntactical structure of the .NET SDK for the Verification API, including any differences that may exist between the API itself and the SDK. For a full reference on Verification API calls and responses, see the Verification API Reference.

The code sample below is an example of how to use the .NET SDK to initiate an SMS Verification request. We've also provided an example that accomplishes the same task using the REST API.

Program.cs
//This example initiates a SMS PIN verification request using the .NET SDK. 
using System.Text.Json;
using Sinch;
using Sinch.Verification.Start.Response;

var sinch = new SinchClient("YOUR_access_key", 
                            "YOUR_access_secret", 
                            "YOUR_project_id");

var verification = sinch.Verification("YOUR_application_key", "YOUR_application_secret");

var response = await verification.Verification.StartSms("YOUR_phone_number");
    
Console.WriteLine(JsonSerializer.Serialize(response, new JsonSerializerOptions()
{
    WriteIndented = true
}));

The Sinch .NET SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, Sinch.Verification.[Endpoint_Category].[Method()].

Endpoint categories

In the Sinch .NET SDK, Verification API endpoints are accessible through the client. The naming convention of the endpoint's representation in the SDK matches the API:

  • Verification.Verification
  • Verification.VerificationStatus

For example:

    using Sinch;
    using Sinch.Verification.Start.Response;

    StartSmsVerificationResponse response = await verification.Verification.StartSms("YOUR_phone_number");

Verification.Verification endpoint category

The Verification.Verification category of the .NET SDK corresponds corresponds to the verifications start endpoint. The mapping between the API operations and corresponding .NET methods are described below:

Verification.VerificationStatus endpoint category

The Verification.VerificationStatus category of the .NET SDK corresponds to the verifications endpoint. The mapping between the API operations and corresponding .NET methods are described below:

Request and query parameters

Requests and queries made using the .NET SDK are similar to those made using the Verification API. Many of the fields are named and structured similarly. For example, consider a request to check on the status of a verification request by using the Identity of the request. One request is using the REST API, and the other is using our .NET SDK:

    var response = await verification.VerificationStatus.GetByIdentity("YOUR_phone_number", VerificationMethod.Sms);
    var request = client.GetAsync("https://verification.api.sinch.com/verification/v1/verifications/" + "YOUR_verification_method" + "/number/" + "YOUR_phone_number").Result;

Note that the path 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 Verification 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 Verification API and their modified counterparts in the Verification API .NET SDK:

API field nameSDK field name
methodMethod
typeType
identityIdentity

Additionally, there are certain fields that are represented by an .NET enum value instead of a string. For example:

API field nameSDK field name
method: "sms"VerificationMethodEx.Sms

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.