# Sinch .NET SDK for SMS 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/sms/getting-started/dotnet-sdk/send-message) 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 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); } } } ``` This example highlights the following required to successfully make an SMS API call using the Sinch .NET SDK: - [Client initialization](#client) - [SMS domain access](#sms-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 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: ```csharp using Sinch; var sinch = new SinchClient(configuration["Sinch:ProjectId"], configuration["Sinch:KeyId"], configuration["Sinch:KeySecret"]); ``` ## Sms 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.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.