0

So I have worked with a Swagger API before but since there is a codegenerator for all API calls i did not really have to worry about that stuff. Now i want to use the following api https://docs.skincay.com/#introduction

public static HttpClient ApiClient { get; set; }

    public static void InitializeClient()
    {
        if (ApiHelper.ApiClient == null)
            ApiHelper.ApiClient = new HttpClient();

        ApiHelper.ApiClient.BaseAddress = new Uri("https://api.skincay.com/v1/");
        ApiHelper.ApiClient.DefaultRequestHeaders.Accept.Clear();
        ApiHelper.ApiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        ApiHelper.ApiClient.DefaultRequestHeaders.Add("Authorization", "Basic clientid:secret");
    }

I followed this guide: https://www.youtube.com/watch?v=aWePkE2ReGw

I just want to work with it in a normal console application but that should not be my problem. The problem is whether the header information i am giving them is right or not since i do not get any response from my calls. I find it really hard working with this documentation and i have not found anyone trying to use this api. I hope someone here can help me with this.

Real
  • 1
  • 1
  • 1
  • Does this answer your question? [Setting Authorization Header of HttpClient](https://stackoverflow.com/questions/14627399/setting-authorization-header-of-httpclient) – Tom W May 24 '20 at 11:27

1 Answers1

1

You should base64 encode your authorization credentials:

var bytes = Encoding.UTF8.GetBytes($"{clientId}:{secret});
var base64 = Convert.ToBase64String(bytes);
ApiClient.DefaultRequestHeaders.Add("Authorization", $"Basic {base64}");

Note: don't forget to replace values from the tutorial with your real uri, clientId and secret

ApiClient.BaseAddress = new Uri("https://docs.skincay.com/#introduction");
string clientId = "bob";
string secret = "derparole";
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
  • Now I get a Newtonsoft.Json.JsonSerializationException in my output window. At least it seems to do something now. This is the call where i get it CsgoItemModel csgoItem = await response.Content.ReadAsAsync(); My CsgoItemModel contains properties only for the information i really need from the calls as shown in the tutorial i have been following – Real May 24 '20 at 11:42