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.
2 replies
-
Hi ,
If you're on v24, there is no longer a /getUserToken call. You should create an API token within the Identity service which would then be linked to an internal Canary user. This is is the token you would use to pass in to the /getSessionToken function. If you're using the gRPC API, the endpoint is 55291. If using the web API, 55293. These are both endpoints of the SaF service.
https://helpcenter.canarylabs.com/t/g9y8gz4/using-the-write-api-version-24 -
Thanks Steve, yes we are running V24.
Unfortunately, when I try following the instructions in that linked article, I get thisAny suggestions why?