How external applications can consume the Management API.
The Management API can be used directly for integrations between Umbraco and external systems.
When consuming the Management API from an external source, you must use the OpenId Connect Client Credentials flow for authorization. Refer to the API Users article for details on setting up Client Credentials.
With a set of Client Credentials in place, you can obtain an access token from the Management API token endpoint: /umbraco/management/api/v1/security/back-office/token.
As shown, the access token should be used as a Bearer token when consuming the Management API.
Also, notice that access tokens have a fixed expiry. While you can keep issuing new tokens for the Client Credentials, please reuse tokens within their lifespan. This will be more performant and avoid flooding the Umbraco database with tokens.
The Management API does not support OpenID Connect Discovery. This is reserved for Members accessing protected content via the Delivery API.
The following code sample demonstrates how to consume the Management API by
Obtaining an access token from the token endpoint, and
Fetching data from the "current user" endpoint.
This sample requires the IdentityModel NuGet package to run.
Program.cs
usingSystem.Net.Http.Json;usingIdentityModel.Client;// the base URL of the Umbraco site - change this to fit your setupconststring host ="https://localhost:44391";var client =newHttpClient();// request a client credentials token from the Management API token endpointvar tokenResponse =awaitclient.RequestClientCredentialsTokenAsync(newClientCredentialsTokenRequest { Address =$"{host}/umbraco/management/api/v1/security/back-office/token", ClientId ="umbraco-back-office-my-client", ClientSecret ="my-client-secret" });if (tokenResponse.IsError||tokenResponse.AccessTokenisnull){Console.WriteLine($"Error obtaining a token: {tokenResponse.ErrorDescription}");return;}// use the access token as Bearer tokenclient.SetBearerToken(tokenResponse.AccessToken);// fetch user data from the "current user" Management API endpointvar apiResponse =awaitclient.GetAsync($"{host}/umbraco/management/api/v1/user/current");var apiUserResponse =await apiResponse .EnsureSuccessStatusCode() .Content .ReadFromJsonAsync<ApiUserResponse>();if (apiUserResponse isnull){Console.WriteLine("Could not parse a user from the API response.");return;}Console.WriteLine($"Hello, {apiUserResponse.Name} ({apiUserResponse.Email})");publicclassApiUserResponse{publicrequiredGuid Id { get; set; }publicrequiredstring Name { get; set; }publicrequiredstring Email { get; set; }}