Related articles

    The REST API accepts token-based authentication.


    Create Bearer Token

    POST /Token


    Input

    Name

    Type

    Description

    grant_type

    string

    Required. Set value to 'client_credentials'.

    client_id

    string

    Required. The id of the application.

    client_secret

    string

    Required. Secret key 1 or key 2 value.


    Example (C#)

    public static string GETToken(string clientID, string clientSecret)
    {
        try
        {
            string url = WebConfigurationManager.AppSettings["GDPRAPIUrl"] + "Token";
            string responseFromServer = string.Empty;
    
            var webRequest = WebRequest.Create(url) as HttpWebRequest;
    
            if (webRequest != null)
            {
                webRequest.Method = "POST";
                webRequest.Timeout = WEB_REQUEST_TIMEUOT;
    
                webRequest.ContentType = "application/x-www-form-urlencoded";
    
                string postData = string.Format("grant_type=client_credentials&client_id={0}&client_secret={1}", clientID, clientSecret);
                byte[] buffer = Encoding.Default.GetBytes(postData);
                if (buffer != null)
                {
                    webRequest.ContentLength = buffer.Length;
                    webRequest.GetRequestStream().Write(buffer, 0, buffer.Length);
                }
            }
    
            using (WebResponse response = webRequest.GetResponse())
            {
                if (((HttpWebResponse)response).StatusCode == HttpStatusCode.OK)
                {
                    using (Stream dataStream = response.GetResponseStream())
                    using (StreamReader reader = new StreamReader(dataStream))
                    responseFromServer = reader.ReadToEnd();
    
                    if (!string.IsNullOrEmpty(responseFromServer))
                    {
                        try
                        {
                            dynamic res = Newtonsoft.Json.JsonConvert.DeserializeObject(responseFromServer);
    
                            return res.access_token;
                        }
                        catch
                        {
                            throw;
                        }
                    }
                    else throw new Exception();
    
                }
                else throw new Exception();
            }
        }
        catch
        {
            return "ERR_NO_TOKEN";
        }
    } 



    Response

    {
       "access_token": "",
       "token_type": "bearer",
       "expires_in": 1209599,
       "userName": "",
       "businessGuid": "",
       ".issued": "Tue, 03 Apr 2018 10:48:10 GMT",
       ".expires": "Tue, 17 Apr 2018 10:48:10 GMT"
    }
    Tags
      Additional articles