Related articles

    The home page of the GdprHq.Io API


    To use this API, you'll need to Authenticate first.

    To see how to handle errors and exceptions, see Error handling article.


    Sample code (C#) for communication with the API

    public static WebRequest GetWebRequestAPI(string token, string method, string endpoint, string json)
    {
        string url = string.Format("{0}api/{1}", WebConfigurationManager.AppSettings["GDPRAPIUrl"], endpoint);
    
        var webRequest = WebRequest.Create(url) as HttpWebRequest;
        if (webRequest != null)
        {
            webRequest.Method = method;
            webRequest.Timeout = WEB_REQUEST_TIMEUOT;
            webRequest.ContentType = "application/json";
            webRequest.Headers.Add("Authorization", "Bearer " + token);
    
            if (!string.IsNullOrEmpty(json))
            {
                using (StreamWriter writer = new StreamWriter(webRequest.GetRequestStream()))
                {
                    writer.Write(json);
                    writer.Flush();
                    writer.Close();
                }
            }
        }
    
        return webRequest;
    }
    
    
    
    public static HttpStatusCode GetStatusCodeFromAPIWebRequest(WebRequest webRequest)
    {
        try
        {
            using (WebResponse response = webRequest.GetResponse())
                return ((HttpWebResponse)response).StatusCode;
        }
        catch (WebException ex)
        {
            if (ex.Status == WebExceptionStatus.ProtocolError)
            {
                var response = ex.Response as HttpWebResponse;
                if (response != null)
                    return response.StatusCode;
                else
                    throw;
            }
            else
                throw;
        }
    }
    
    
    
    
    
    public static object GetObjectFromAPIWebRequest(WebRequest webRequest)
    {
        string responseFromServer = string.Empty;
    
        try
        {
            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
                        {
                            var res = Newtonsoft.Json.JsonConvert.DeserializeObject(responseFromServer);
    
                            return res;
                        }
                        catch
                        {
                            throw;
                        }
                    }
                    else throw new Exception();
    
                }
                else throw new Exception();
            }
        }
        catch
        {
            throw;
        }
    }
    Tags
      Additional articles