# .NET SDK 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 . Important .NET SDK links: The following links are available for your reference: - [Sinch .NET SDK repository](https://github.com/sinch/sinch-sdk-dotnet) - [.NET SDK releases](https://github.com/sinch/sinch-sdk-dotnet/releases) ## 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](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"])); ``` #### Application Authentication Voice API To start using the Voice API with the SDK, you need to initialize the main client class with your credentials from your Sinch [dashboard](https://dashboard.sinch.com) and additionally create a Voice client object that uses your [Voice app credentials](https://dashboard.sinch.com/voice/apps). 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_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: ```cpp Initialize client for only Voice using Sinch; var sinch = new SinchClient(default, default, default); var voice = sinch.Voice("YOUR_application_key", "YOUR_application_secret"); ``` Verification API To start using the Verification API with the SDK, you need to initialize the main client class with your credentials from your Sinch [dashboard](https://dashboard.sinch.com) and additionally create a Verification client object that uses your [Verification app credentials](https://dashboard.sinch.com/verification/apps). 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"); var verification = sinch.Verification("YOUR_application_key", "YOUR_application_secret"); ``` Or, if you only need to use Verification API: ```cpp Initialize client for only Verification using Sinch; var sinch = new SinchClient(default, default, default); var verification = sinch.Verification("YOUR_application_key", "YOUR_application_secret"); ``` ## Domains The Java SDK currently supports the following products: Numbers SMS Conversation Voice Verification ### 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](/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); } } } ``` 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. ### 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](/docs/sms/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. SDK 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{"YOUR_recipient_phone_number"} }); Console.WriteLine(JsonSerializer.Serialize(response, new JsonSerializerOptions() { WriteIndented = true })); REST API ```csharp using System.Text; using Newtonsoft.Json; public class SMS { public string from { get; set; } public string[] to { get; set; } public string body { get; set; } public SMS(string from, string[] to, string body) { this.from = from; this.to = to; this.body = body; } public async void sendSMS(SMS sms, string servicePlanId, string apiToken) { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Add("Authorization", "Bearer " + apiToken); string json = JsonConvert.SerializeObject(sms); var postData = new StringContent(json, Encoding.UTF8, "application/json"); var request = await client.PostAsync("https://us.sms.api.sinch.com/xms/v1/" + servicePlanId + "/batches", postData); var response = await request.Content.ReadAsStringAsync(); Console.WriteLine(response); } } } ``` 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()]`. 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: ```csharp 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{"YOUR_recipient_phone_number"} }); ``` The `Sms.Batches` category of the .NET SDK corresponds to the [batches](/docs/sms/api-reference/sms/batches/) endpoint. The mapping between the API operations and corresponding .NET methods are described below: | API operation | SDK method | | --- | --- | | [Send](/docs/sms/api-reference/sms/batches/sendsms) | `Send()` | | [List batches](docs/sms/api-reference/sms/batches/listbatches) | `List()` | | [Dry run](/docs/sms/api-reference/sms/batches/dry_run) | `DryRun()` | | [Get a batch message](/docs/sms/api-reference/sms/batches/getbatchmessage) | `Get()` | | [Update a batch message](/docs/sms/api-reference/sms/batches/updatebatchmessage) | `Update()` | | [Replace a batch](/docs/sms/api-reference/sms/batches/replacebatch) | `Replace()` | | [Cancel a batch message](/docs/sms/api-reference/sms/batches/cancelbatchmessage) | `Cancel()` | | [Send delivery feedback for a message](/docs/sms/api-reference/sms/batches/deliveryfeedback) | `SendDeliveryFeedback()` | The `Sms.DeliveryReports` category of the .NET SDK corresponds to the [delivery_report and delivery_reports](/docs/sms/api-reference/sms/delivery-reports/) endpoints. The mapping between the API operations and corresponding .NET methods are described below: | API operation | SDK method | | --- | --- | | [Retrieve a delivery report](/docs/sms/api-reference/sms/delivery-reports/getdeliveryreportbybatchid) | `Get()` | | [Retrieve a recipient delivery report](/docs/sms/api-reference/sms/delivery-reports/getdeliveryreportbyphonenumber) | `GetForNumber()` | | [Retrieve a list of delivery reports](/docs/sms/api-reference/sms/delivery-reports/getdeliveryreports) | `List()` | The `Sms.Groups` category of the .NET SDK corresponds to the [groups](/docs/sms/api-reference/sms/groups/) endpoint. The mapping between the API operations and corresponding .NET methods are described below: | API operation | SDK method | | --- | --- | | [List groups](/docs/sms/api-reference/sms/groups/listgroups) | `List()` | | [Create a group](/docs/sms/api-reference/sms/groups/creategroup) | `Create()` | | [Retrieve a group](/docs/sms/api-reference/sms/groups/retrievegroup) | `Get()` | | [Update a group](/docs/sms/api-reference/sms/groups/updategroup) | `Update()` | | [Replace a group](/docs/sms/api-reference/sms/groups/replacegroup) | `Replace()` | | [Delete a group](/docs/sms/api-reference/sms/groups/deletegroup) | `Delete()` | | [List group member phone numbers](/docs/sms/api-reference/sms/groups/getmembers) | `ListMembers()` | The `Sms.Inbounds` category of the .NET SDK corresponds to the [inbounds](/docs/sms/api-reference/sms/inbounds/) endpoint. The mapping between the API operations and corresponding .NET methods are described below: | API operation | SDK method | | --- | --- | | [List incoming messages](/docs/sms/api-reference/sms/inbounds/listinboundmessages) | `List()` | | [Retrieve inbound message](/docs/sms/api-reference/sms/inbounds/retrieveinboundmessage) | `Get()` | 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: SDK ```csharp BatchId = "{BATCH_ID}" ``` REST API ```json "batch_id": "{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: SDK ```csharp smsResponse = sinchClient.Sms.Batches.Get("BATCH_ID"); ``` REST API ```JSON url = "https://us.SMS.api.sinch.com/v1/" + service_plan_id + "/batches/" + 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. 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 name | SDK field name | | --- | --- | | `type` | `Type` | | `from` | `From` | | `recipient_msisdn` | `recipientMsisdn` | Additionally, some fields which require string values in the SMS API have enum values in the .NET SDK. Consider the following example: SDK ```csharp SmsType Type = SmsType.MtText; ``` REST API ```JSON "type": "mtText" ``` 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](/docs/conversation/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): SDK 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 { new ChannelIdentity { AppId = "YOUR_app_id", Identity = "RECIPIENT_number", Channel = new ConversationChannel("SMS") } } } }, ChannelProperties = new Dictionary { { "SMS_SENDER", "YOUR_sms_sender" } } }); Console.WriteLine(JsonSerializer.Serialize(response, new JsonSerializerOptions() { WriteIndented = true })); REST API ```csharp // Find your App ID at dashboard.sinch.com/convapi/apps // Find your Project ID at dashboard.sinch.com/settings/project-management // Get your Access Key and Access Secret at dashboard.sinch.com/settings/access-keys using System; using System.Net.Http; using System.Threading.Tasks; using System.Text; using System.Text.Json; using System.Net.Http.Headers; public class Program { public static async Task Main() { System.Net.Http.HttpClient client = new(); string base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes("YOUR_access_key:YOUR_access_secret")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(@"Basic", base64String); string json = JsonSerializer.Serialize(new { app_id = "YOUR_app_id", recipient = new { identified_by = new { channel_identities = new[] { new { channel = "SMS", identity = "RECIPIENT_number" } }, } }, message = new { text_message = new { text = "This is a text message." } }, channel_properties = new { SMS_SENDER = "YOUR_sms_sender" } }); using StringContent postData = new(json, Encoding.UTF8, "application/json"); var ProjectId = "YOUR_project_id"; var Region = "us"; using HttpResponseMessage request = await client.PostAsync("https://" + Region + ".conversation.api.sinch.com/v1/projects/" + ProjectId + "/messages:send", postData); string response = await request.Content.ReadAsStringAsync(); Console.WriteLine(response); } } ``` 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()]`. 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: ```csharp 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 { new ChannelIdentity { AppId = "YOUR_app_id", Identity = "RECIPIENT_number", Channel = new ConversationChannel("SMS") } } } }, ChannelProperties = new Dictionary { { "SMS_SENDER", "YOUR_sms_sender" } } }); ``` The `Messages` category of the .NET SDK corresponds to the [messages](/docs/conversation/api-reference/conversation/messages/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [Send a message](/docs/conversation/api-reference/conversation/messages/messages_sendmessage) | `Send` | | [Get a message](/docs/conversation/api-reference/conversation/messages/messages_getmessage) | `Get` | | [Delete a message](/docs/conversation/api-reference/conversation/messages/messages_deletemessage) | `Delete` | | [List messages](/docs/conversation/api-reference/conversation/messages/messages_listmessages) | `List` | | [Update a message's metadata](/docs/conversation/api-reference/conversation/messages/messages_updatemessagemetadata) | `Update` | The `Apps` category of the .NET SDK corresponds to the [apps](/docs/conversation/api-reference/conversation/app/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [List all apps for a given project](/docs/conversation/api-reference/conversation/app/app_listapps) | `List` | | [Create an app](/docs/conversation/api-reference/conversation/app/app_createapp) | `Create` | | [Get an app](/docs/conversation/api-reference/conversation/app/app_getapp) | `Get` | | [Delete an app](/docs/conversation/api-reference/conversation/app/app_deleteapp) | `Delete` | | [Update an app](/docs/conversation/api-reference/conversation/app/app_updateapp) | `Update` | The `Contacts` category of the .NET SDK corresponds to the [contacts](/docs/conversation/api-reference/conversation/contact/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [List contacts](/docs/conversation/api-reference/conversation/contact/contact_listcontacts) | `List` or `ListAuto` | | [Create a contact](/docs/conversation/api-reference/conversation/contact/contact_createcontact) | `Create` | | [Get a contact](/docs/conversation/api-reference/conversation/contact/contact_getcontact) | `Get` | | [Delete a contact](/docs/conversation/api-reference/conversation/contact/contact_deletecontact) | `Delete` | | [Update a contact](/docs/conversation/api-reference/conversation/contact/contact_updatecontact) | `Update` | | [Merge two contacts](/docs/conversation/api-reference/conversation/contact/contact_mergecontact) | `Merge` | | [Get channel profile](/docs/conversation/api-reference/conversation/contact/contact_getchannelprofile) | `GetChannelProfile` | The `Conversations` category of the .NET SDK corresponds to the [conversations](docs/conversation/api-reference/conversation/conversation/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [List conversations](/docs/conversation/api-reference/conversation/conversation/conversation_listconversations) | `List` or `ListAuto` | | [Create a conversation](/docs/conversation/api-reference/conversation/conversation/conversation_createconversation) | `Create` | | [Get a conversation](/docs/conversation/api-reference/conversation/conversation/conversation_getconversation) | `Get` | | [Delete a conversation](/docs/conversation/api-reference/conversation/conversation/conversation_deleteconversation) | `Delete` | | [Update a conversation](/docs/conversation/api-reference/conversation/conversation/conversation_updateconversation) | `Update` | | [Stop conversation](/docs/conversation/api-reference/conversation/conversation/conversation_stopactiveconversation) | `Stop` | | [Inject a message](/docs/conversation/api-reference/conversation/conversation/conversation_injectmessage) | `InjectMessage` | | [Inject an event](/docs/conversation/api-reference/conversation/conversation/events_injectevent) | `InjectEvent` | The `Events` category of the .NET SDK corresponds to the [events](/docs/conversation/api-reference/conversation/events/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [Send an event](/docs/conversation/api-reference/conversation/events/events_sendevent) | `Send` | | [Get an event](/docs/conversation/api-reference/conversation/events/events_getevent) | `Get` | | [Delete an event](/docs/conversation/api-reference/conversation/events/events_deleteevents) | `Delete` | | [List events](/docs/conversation/api-reference/conversation/events/events_listevents) | `List` or `ListAuto` | The `Transcoding` category of the .NET SDK corresponds to the [messages:transcode](/docs/conversation/api-reference/conversation/transcoding/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [Transcode a message](/docs/conversation/api-reference/conversation/transcoding/transcoding_transcodemessage) | `Transcode` | The `Capability` category of the .NET SDK corresponds to the [capability](/docs/conversation/api-reference/conversation/capability/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [Capability lookup](/docs/conversation/api-reference/conversation/capability/capability_querycapability) | `Lookup` | The `Webhooks` category of the .NET SDK corresponds to the [webhooks](/docs/conversation/api-reference/conversation/webhooks/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [List webhooks](/docs/conversation/api-reference/conversation/webhooks/webhooks_listwebhooks) | `List` | | [Create a new webhook](/docs/conversation/api-reference/conversation/webhooks/webhooks_createwebhook) | `Create` | | [Get a webhook](/docs/conversation/api-reference/conversation/webhooks/webhooks_getwebhook) | `Get` | | [Update an existing webhook](/docs/conversation/api-reference/conversation/webhooks/webhooks_updatewebhook) | `Update` | | [Delete an existing webhook](/docs/conversation/api-reference/conversation/webhooks/webhooks_deletewebhook) | `Delete` | The `TemplatesV2` category of the .NET SDK corresponds to the [Templates-V2](/docs/conversation/api-reference/template/templates-v2/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [List all templates belonging to a project ID](/docs/conversation/api-reference/template/templates-v2/templates_v2_listtemplates) | `List` | | [Creates a template](/docs/conversation/api-reference/template/templates-v2/templates_v2_createtemplate) | `Create` | | [Lists translations for a template](/docs/conversation/api-reference/template/templates-v2/templates_v2_deletetemplate) | `ListTranslations` | | [Updates a template](/docs/conversation/api-reference/template/templates-v2/templates_v2_updatetemplate) | `Update` | | [Get a template](/docs/conversation/api-reference/template/templates-v2/templates_v2_gettemplate) | `Get` | | [Delete a template](/docs/conversation/api-reference/template/templates-v2/templates_v2_deletetemplate) | `Delete` | 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: SDK ```csharp AppId = "YOUR_app_id" ``` REST API ```JSON "app_id": "{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: SDK ```csharp var response = await sinch.Conversation.Messages.Get( messageId = "YOUR_message_id", messagesSource = "CONVERSATION_SOURCE" ) ``` REST API ```JSON url = "https://us.conversation.api.sinch.com/v1/projects/" + project_id + "/messages/" + YOUR_message_id payload = { "messages_source": "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. 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](/docs/voice/api-reference/voice). 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. SDK 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 })); REST API ```cpp using System; using System.Net.Http; using System.Threading.Tasks; using System.Text; using System.Text.Json; using System.Net.Http.Headers; class Program { private const string _from = ""; private const string _to = ""; private const string _key = ""; private const string _secret = ""; public static async Task Main() { System.Net.Http.HttpClient client = new(); string base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes(_key + ":" + _secret)); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(@"Basic", base64String); string json = JsonSerializer.Serialize(new { method = "ttsCallout", ttsCallout = new { cli = "+14045001000", destination = new { type = "number", endpoint = _to }, locale = "en-US", text = "Hello, this is a call from Sinch." } }); using StringContent postData = new(json, Encoding.UTF8, "application/json"); using HttpResponseMessage request = await client.PostAsync("https://calling.api.sinch.com/calling/v1/callouts", postData); string response = await request.Content.ReadAsStringAsync(); Console.WriteLine(response); } } ``` 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()]`. 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: ```cpp 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." }); ``` The `Voice.Callouts` category of the .NET SDK corresponds corresponds to the [callouts](/docs/voice/api-reference/voice/callouts/) endpoint. The mapping between the API operations and corresponding .NET methods are described below: | API operation | SDK method | | --- | --- | | [Makes a Text-to-speech callout](/docs/voice/api-reference/voice/callouts/callouts#callouts/callouts/request) | `Tts()` | | [Makes a Conference callout](/docs/voice/api-reference/voice/callouts/callouts#callouts/callouts/request) | `Conference()` | | [Makes a Custom callout](/docs/voice/api-reference/voice/callouts/callouts#callouts/callouts/request) | `Custom()` | The `Voice.Calls` category of the .NET SDK corresponds corresponds to the [calls](/docs/voice/api-reference/voice/calls/) endpoint. The mapping between the API operations and corresponding .NET methods are described below: | API operation | SDK method | | --- | --- | | [Update a call in progress](/docs/voice/api-reference/voice/calls/calling_updatecall) | `Update()` | | [Get information about a call](/docs/voice/api-reference/voice/calls/calling_getcallresult) | `Get()` | | [Manage a call with `callLeg`](/docs/voice/api-reference/voice/calls/calling_managecallwithcallleg) | `ManageWithCallLeg()` | The `Voice.Conferences` category of the .NET SDK corresponds corresponds to the [conferences](/docs/voice/api-reference/voice/conferences/) endpoint. The mapping between the API operations and corresponding .NET methods are described below: | API operation | SDK method | | --- | --- | | [Get information about a conference](/docs/voice/api-reference/voice/conferences/calling_getconferenceinfo) | `Get()` | | [Manage a conference participant](/docs/voice/api-reference/voice/conferences/calling_manageconferenceparticipant) | `ManageParticipant()` | | [Remove a participant from a conference](/docs/voice/api-reference/voice/conferences/calling_kickconferenceparticipant) | `KickParticipant()` | | [Remove all participants from a conference](/docs/voice/api-reference/voice/conferences/calling_kickconferenceall) | `KickAll()` | The `Voice.Applications` category of the .NET SDK corresponds corresponds to the [configuration](/docs/voice/api-reference/voice/applications/) endpoint. The mapping between the API operations and corresponding .NET methods are described below: | API operation | SDK method | | --- | --- | | [Return all the numbers assigned to an application](/docs/voice/api-reference/voice/applications/configuration_getnumbers) | `GetNumbers()` | | [Assign a number or list of numbers to an application](/docs/voice/api-reference/voice/applications/configuration_updatenumbers) | `AssignNumbers()` | | [Unassign a number from an application](/docs/voice/api-reference/voice/applications/configuration_unassignnumber) | `UnassignNumber()` | | [Return the callback URLs for an application](/docs/voice/api-reference/voice/applications/configuration_getcallbackurls) | `GetCallbackUrls()` | | [Update the callback URL for an application](/docs/voice/api-reference/voice/applications/configuration_updatecallbackurls) | `UpdateCallbackUrls()` | | [Returns information about a number](/docs/voice/api-reference/voice/applications/calling_querynumber) | `QueryNumber()` | 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: ```cpp var response = await voice.calls.Get(CallId); ``` ```cpp 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. 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. 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](/docs/verification/api-reference/verification). 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. SDK 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 })); REST API ```cpp using System.Text; using System.Text.Json; class Program { private const string _to = ""; private const string _key = ""; private const string _secret = ""; private const string _sinchUrl = "https://verification.api.sinch.com/verification/v1/verifications"; static async Task Main(string[] args) { await SendSMSPinWithBasicAuth(); } private static async Task SendSMSPinWithBasicAuth() { using (var _client = new HttpClient()) { var requestBody = GetSMSVerificationRequestBody(); 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(request.StatusCode + " " + request.ReasonPhrase); Console.WriteLine(await request.Content.ReadAsStringAsync()); request.EnsureSuccessStatusCode(); } } public static StringContent GetSMSVerificationRequestBody() { var myData = new { identity = new { type = "number", endpoint = _to }, method = "sms", }; return new StringContent( JsonSerializer.Serialize(myData), Encoding.UTF8, Application.Json ); } } ``` 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()]`. 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: ```cpp using Sinch; using Sinch.Verification.Start.Response; StartSmsVerificationResponse response = await verification.Verification.StartSms("YOUR_phone_number"); ``` The `Verification.Verification` category of the .NET SDK corresponds corresponds to the [verifications start](/docs/verification/api-reference/verification/verifications-start/) endpoint. The mapping between the API operations and corresponding .NET methods are described below: | API operation | SDK method | | --- | --- | | [Start an SMS PIN verification request](/docs/verification/api-reference/verification/verifications-start/startverification) | `StartSms()` | | [Start a FlashCall verification request](/docs/verification/api-reference/verification/verifications-start/startverification) | `StartFlashCall()` | | [Start a Phone Call verification request](/docs/verification/api-reference/verification/verifications-start/startverification) | `StartCallout()` | | [Start a Data verification request](/docs/verification/api-reference/verification/verifications-start/startverification) | `StartSeamless()` | | [Report an SMS PIN verification code by the identity of the recipient](/docs/verification/api-reference/verification/verifications-report/reportverificationbyidentity) | `ReportSmsByIdentity()` | | [Report a FlashCall verification by the identity of the recipient](/docs/verification/api-reference/verification/verifications-report/reportverificationbyidentity) | `ReportFlashCallByIdentity()` | | [Report a Phone Call verification code by the identity of the recipient](/docs/verification/api-reference/verification/verifications-report/reportverificationbyidentity) | `ReportCalloutByIdentity()` | | [Report an SMS PIN verification code by the ID of the verification request](/docs/verification/api-reference/verification/verifications-report/reportverificationbyid) | `ReportSmsById()` | | [Report a FlashCall verification by the ID of the verification request](/docs/verification/api-reference/verification/verifications-report/reportverificationbyid) | `ReportFlashCallById()` | | [Report a Phone Call verification code by the ID of the verification request](/docs/verification/api-reference/verification/verifications-report/reportverificationbyid) | `ReportCalloutById()` | The `Verification.VerificationStatus` category of the .NET SDK corresponds to the [verifications](/docs/verification/api-reference/verification/verification-status/) endpoint. The mapping between the API operations and corresponding .NET methods are described below: | API operation | SDK method | | --- | --- | | [Get the status of a verification by the ID of the verification request](/docs/verification/api-reference/verification/verification-status/verificationstatusbyid) | `GetById()` | | [Get the status of a verification by the identity of the recipient](/docs/verification/api-reference/verification/verification-status/verificationstatusbyidentity) | `GetByIdentity()` | | [Get the status of a verification by a reference value](/docs/verification/api-reference/verification/verification-status/verificationstatusbyreference) | `GetByReference()` | 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: ```cpp var response = await verification.VerificationStatus.GetByIdentity("YOUR_phone_number", VerificationMethod.Sms); ``` ```cpp 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. 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 name | SDK field name | | --- | --- | | `method` | `Method` | | `type` | `Type` | | `identity` | `Identity` | Additionally, there are certain fields that are represented by an .NET enum value instead of a string. For example: | API field name | SDK field name | | --- | --- | | `method: "sms"` | `VerificationMethodEx.Sms` | 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.