SDK for .NET
Introduction
The Docplanner SDK is built on .NET Standard 2.0, supporting both .NET Framework 4.6.1+ and .NET Core 2.0+ projects.
Requirements
No special requirements are needed. The package includes dependencies:
Newtonsoft.Json
(version 12.0.0 or higher)System.ComponentModel.Annotations
(version 5.0.0 or higher)
Setup
Obtaining the Package
The package is available in the Docplanner public repository.
- Add the following package source to your NuGet configuration:
https://pkgs.dev.azure.com/docplanner/c4fa307b-7faf-45b9-a23f-faace862ad8f/_packaging/integrations%40Release/nuget/v3/index.json
- Search for and install the
Integrations.Api.Sdk
package via your NuGet package manager.
Authentication
The SDK uses OAuth 2.0 protocol to authenticate against API endpoints.
- Obtain a token by calling:Use the appropriate grant type and scope, along with your
https://www.{domain}/oauth/v2/token
client_id
andclient_secret
for basic authorization. For example:var values = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("grant_type", "client_credentials"), new KeyValuePair<string, string>("scope", "integration") }; requestMessage.Headers.Add("Authorization", $"Basic {client_id}:{client_secret}");
- Use the acquired token in the Authorization header for all API requests:
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "your_token");
For more information on authentication, see the authentication documentation.
Using the Client
Client Naming
Clients are named according to the tags specified in the API documentation. For example, if there is a Services
tag, the corresponding client will be named ServicesClient
.
Example Usage
Below is an example of retrieving a list of facilities using the FacilitiesClient
.
Set up an HttpClient
with the base URI:
var httpClient = new HttpClient()
{
BaseAddress = new Uri("https://www.{domain}/api/v3/integration")
};
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await GetToken());
var facilitiesClient = new FacilitiesClient(httpClient);
var result = await facilitiesClient.FacilitiesGetAsync();
Sample Applications
Sample applications are available for the .NET SDK.
Remember: You will need to replace client_id
and client_secret
with your own values.
Console Application:
A simple console app using the defaultHttpClient
.
Download here.Web Application (Custom Handler):
A sample web application utilizing a customHttpMessageHandler
to manage token acquisition and storage.
Download here.Web Application (Identity Handler):
A sample web application leveraging theIdentityModel.AspNetCore
package to simplify OAuth2 token usage.
Download here.