ramthechosenone
9/3/2019 - 2:47 PM

REST Call C# Bearer token GET

var client = new RestClient(endpoint + "/apiURL");
var request = new RestRequest(Method.GET);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Content-Type", "application/json");
//if it needs a bearer token
request.AddHeader("Authorization", "Bearer " + token);

try
{
    IRestResponse response = client.Execute(request);
    string responseStatus = " ";
    
    if (response.IsSuccessful)
    {
        try
        {
          //cast response into an object
        }
        catch (Exception ex)
        {
            responseStatus = ex.GetBaseException().ToString();
            log.Error($"Error parsing response from iMIS -{ex.ToString()}");
        }
    }
    else
    {
        responseStatus = response.Content.ToString();
        log.Error($"Response not successful");
    }
}
catch (Exception ex)
{
    log.Error($"Error fetching from iMIS -{ex.ToString()}");
    throw ex;
}