ICD API Authentication

In order to be able to use the ICD APIs you need to follow these steps:

Many programming languages have APIs that you could use to make the process easier. Below you will find and example in C# using .NET. You may find more examples in other programming languages at our ICD API Samples GitHub repository


using System.Net.Http;
using System.Net.Http.Headers;

//...

var tokenEndpoint = "https://icdaccessmanagement.who.int/connect/token";
var clientId = "..."; //of course not a good idea to put id and secret in the source code
var clientSecret = "..."; //you could read from an encyrpted source in the production
var scope = "icdapi_access";

tokenClient = new TokenClient(tokenEndpoint,
				clientId,
				clientSecret);

//We request the for an access token
tokenResponse = await tokenClient.RequestClientCredentialsAsync(scope);

var client = new HttpClient();
//Place the token at the httpclient that we are going to use at the future requests
client.SetBearerToken(tokenResponse.AccessToken);

//prepare a request to the API
request = new HttpRequestMessage(HttpMethod.Get, "https://id.who.int/icd/entity");

//put an accept header for application/json
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
request.Headers.AcceptLanguage.Add(new StringWithQualityHeaderValue("en"));

//call the API
var response = await client.SendAsync(request);
if (!response.IsSuccessStatusCode)
{
      Console.WriteLine(response.StatusCode);
}

var content = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(content);