This topic will get you started with the HotDocs Advance API, using the resource owner authentication flow.
In this Topic Hide
1. Log into the API Client Management application
3. Add a service principal to the client
To view, create, and manage your API clients, you should log in to the HotDocs Advance API Management application:
A client is required to make requests to the Advance API. For this example, select a ResourceOwner flow type and Query scope.
The service principal is an account in Advance that acts on behalf of a client. Clients that use the resource owner flow require an associated service principal user.
You only need to add a service principal if your client uses the Resource Owner authentication flow.
Note: You must remember this password; it cannot be viewed again beyond this page. You will require the password when making requests to the Advance API.
Once the client and service principal are activated, you can use them to retrieve an access token from the API.
HotDocs Advance requires you to supply an access token with your API requests, to verify that you are authorized to make that request.
The access token request requires you to provide the following data:
To retrieve a token using the Resource Owner flow, use the example below to request an access token from the API.
using System; using System.Net.Http; using System.Text; using System.Threading.Tasks;
namespace HotDocsAdvanceApiExamples { public class ResourceOwnerAuthorization { // These are the credentials required for retrieving an access token using the resource owner flow. // You will replace these credentials with those for a client you create yourself, // using the Advance Client Management Application. See the API help guide for more information. private string clientName = "ab3e4544-b595-4681-b0ea-c7c18c9b63f6"; private string servicePrincipalName = "ExampleServicePrincipalA"; private string servicePrincipalPassword = "examplePassword";
public async Task<string> GetResourceOwnerToken() { // Create the access token request var request = CreateHttpRequestMessage();
//Send token request to Advance using (var client = new HttpClient()) { var response = await client.SendAsync(request);
// Return the retrieved access token return response.Content.ReadAsStringAsync().Result; } }
private HttpRequestMessage CreateHttpRequestMessage() { var tokenUrl = string.Format("https://yourtenancy.yourorganization.com/HdaAuth/Authorize/ServicePrincipalLogIn");
return new HttpRequestMessage { RequestUri = new Uri(tokenUrl), Method = HttpMethod.Post, Content = GetRequestContent() }; }
private StringContent GetRequestContent() { var json = "{" + string.Format("'ClientName' : '{0}', 'PrincipalName' : '{1}', 'PrincipalPassword' : '{2}'", clientName, servicePrincipalName, servicePrincipalPassword) + "}"; return new StringContent(json, Encoding.UTF8, "application/json"); } } }
The Advance API URL is the base URL to which you make API requests.
The URL consists of the path to the Advance API application and the API version you want to use. The format of the URL is typically:
Where:
You will need to know this URL when looking up the API documentation and making requests to the API endpoints.
For example, the URL for a request to get all work items in the tenancy might look like:
Keep a note of this URL for the next step.
Once you have retrieved an access token, you can use it to sign the requests you make to the Advance API. For example, you can use the example below to create a new user. Make sure you change the createUserUrl to use your API base URL.
using System; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks;
namespace HotDocsAdvanceApiExamples { public class UserRequest { public async Task<HttpStatusCode> CreateUser(string token) { // Create the 'create user' request var userId = Guid.NewGuid(); var request = CreateHttpRequestMessage(userId);
//Send create user request to Advance using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); var response = await client.SendAsync(request); return response.StatusCode; } }
private HttpRequestMessage CreateHttpRequestMessage(Guid userId) { // Create the request for the 'create user' API endpoint var createUserUrl = string.Format("https://yourtenancy.yourorganization.com/HdaApi/rest/v1.1/Users/{0}", userId);
return new HttpRequestMessage { RequestUri = new Uri(createUserUrl), Method = HttpMethod.Post, Content = GetRequestContent() }; }
private StringContent GetRequestContent() { // Generate the JSON request body required by the 'create user' method var json = "{ 'firstName': 'Emma', 'lastName': 'MacDiarmid', 'emailAddress': 'emma.macdiarmid@example.com', 'roles': [ 'SiteAdministrator' ], 'sendEmail': true }"; return new StringContent(json, Encoding.UTF8, "application/json"); } } }
See Using the API Overview for more details about using the API, including code examples for various requests.
The Advance API documentation also contains information about the types of requests you can make using the API.
You can view the latest reference documentation for the Advance API at https://yourorganization.com/HdaApi/rest/documentation/index.html, where yourorganization.com is the domain under which your Advance deployment is located.