# Sinch .NET SDK for Voice 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/voice/getting-started/dotnet_sdk/make-phone-call) 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 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); } } ``` This example highlights the following required to successfully make a Voice API call using the Sinch .NET SDK: - [Client initialization](#client) - [Voice domain](#voice-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 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"); ``` ## Voice 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.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.