SDK for .NET
Introduction
Our SDK is created in .NET Standard 2.0, so we are supporting .NET Framework 4.6.1+ and .NET Core 2.0+
Requirements
This package doesn't have special requirements. Within package we bundle Newtonsoft.Json 12.0.0+
and System.ComponentModel.Annotations 5.0.0+
Setup
Getting package
Package can be found in Docplanner public repository
You need to add new package source https://pkgs.dev.azure.com/docplanner/c4fa307b-7faf-45b9-a23f-faace862ad8f/_packaging/integrations%40Release/nuget/v3/index.json
in NuGet config.
After that look for package Integrations.Api.Sdk
in package manager.
Authentication
We use OAuth 2.0 protocol for endpoints authentication.
You need to get token from endpoint https://www.{domain}/oauth/v2/token
with specific grand type and scope using your client_id
and client_secret
for basic authorization.
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}");
You must use token in Authorization
header to access API endpoints.
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "your_token");
More information about authentication you can find here.
Using Client
Client naming
Client are named according to tags in API Docs
So if we have Services
tag then client will be named ServicesClient
.
Using Client
As seen in example we call FacilitiesClient
to get list of facilities. We create HttpClient
with base URI https://www.{domain}/api/v3/integration
.
var httpClient = new HttpClient()
{
BaseAddress = new Uri("https://www.{domain}/api/v3/integration")
};
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await GetToken()); //get token
var apiTest = new FacilitiesClient(httpClient);
var result = await apiTest.FacilitiesGetAsync();
Samples
For .NET SDK we have sample applications.
Remember, you need to replace client_id
and client_secret
in application.
Console application
Simple console application using default HttpClient.
You can download it here.
Web Application(Custom Handler)
Simple web application with usage of custom written HttpMessageHandler
, to acquire and store token.
You can download it here.
Web Application(Identity Handler)
Simple web application using package IdentityModel.AspNetCore
which simplifies usage of OAuth 2 tokens.
You can download it here.