2

I'm facing a strange error with the usage of the GITHUB API. When I contact them with cURL it's like:

curl.exe -H "Accept: application/vnd.github.cloud-9-preview+json+scim" -H "Authorization: Bearer TOKEN" https://api.github.com/scim/v2/organizations/[ORG]/Users

When I try to take it to C#, if became:

 using (var cl = new HttpClient())
        {
            cl.DefaultRequestHeaders.Add("Accept", "application/vnd.github.cloud-9-preview+json+scim");
            cl.DefaultRequestHeaders.Add("Authorization", "Bearer " + "TOKEN");
            var val = cl.GetStringAsync("https://api.github.com/scim/v2/organizations/[ORG]/Users").Result;
        }

When I run my cURL everything works fine but when I try the same on C# I got a 403 Error.

Could it be related to the "Accept" non standard field?

Ziba Leah
  • 2,484
  • 7
  • 41
  • 60
  • 1
    Run fiddler and see what http request exactly is sent in both cases. That will help you with similar issues in future. – Evk Dec 12 '17 at 20:25

1 Answers1

0

I find out that the GITHUB API requires to have the User-Agent header Set.

Setting it as "curl" made it.

using (var cl = new HttpClient())
        {
            cl.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/vnd.github.cloud-9-preview+json+scim"));
            cl.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "token");
            cl.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("curl", "7.46.0"));
            var val = cl.GetStringAsync("https://api.github.com/scim/v2/organizations/[ORG]/Users").Result;
        }
Ziba Leah
  • 2,484
  • 7
  • 41
  • 60