0

Basic web API usage

I'm trying to write a little tool to put data into Canary tags through the Web API but am hitting my lack of knowledge on such things.

Looking at the endpoints in the Identity tile, I see that the REST API port is 55353. But if I go to http://localhost:55353/api/getUserToken I get ERR_EMPTY_RESPONSE and if I use https I get a 404 error.

In my C# code, I calling that URL with username, password, timezone and application in the request body and I'm getting the same as I get in the browser.

 

Is there an example starting project for interacting with the Canary web API? Any hints what I'm doing wrong? Here's my code for getting a user token:

       public static async Task<string> GetUserTokenAsync(string server, string username, string password)
        {
            string port = "55353";
            //string url = $"https://{server}/api/getUserToken";
            string url = $"http://{server}:{port}/api/getUserToken";   // not secure
            var requestBody = new
            {
                username = username,
                password = password,
                timezone = "UTC",
                application = "WebServiceCollector"
            };

            string json = JsonSerializer.Serialize(requestBody);
            HttpContent content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");

            HttpResponseMessage response = await client.PostAsync(url, content);
            response.EnsureSuccessStatusCode();

            string responseBody = await response.Content.ReadAsStringAsync();
            var responseData = JsonSerializer.Deserialize<Dictionary<string, string>>(responseBody);

            return responseData["userToken"];
        }

 

 

Regards,

 

Alistair.

Reply

null

Content aside

print this pagePrint this page
  • yesterdayLast active
  • 5Views
  • 2 Following