please ignore this.. resolved! thanks
Again, it seems like you haven't read documentation before asking question.
Anton
No, thats my C# problem, not related to Traccar
One of the problems that I see is that you are not using correct API endpoint, which is documented.
What do you mean by connect using IP Point?
What I found in the doc is:
——-
Security
basicAuth
Type: basic
Description:
Basic HTTP authorization with email and password
——
Do you mean the port?
I still able to connect to 8082 and 5055 and I still checking this.
I mean URL, which is completely incorrect.
noted and thanks Anton..
my latest try below has succeed to create session, but what I don't understand why the "Token" is empty?, as I read from the doc there is no token parameter required to access the API functions.. or I still missed something? .. (
string url = "http://mydomain.com:8082/api/session";
var pairs = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("email", email),
new KeyValuePair<string, string>("password", password)
};
var client = new HttpClient();
client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "x-www-form-urlencoded");
var content = new FormUrlEncodedContent(pairs);
var response = client.PostAsync(url, content).Result;
HttpStatusCode statusCode = response.StatusCode;
switch (statusCode)
{
case HttpStatusCode.OK:
{
response.EnsureSuccessStatusCode();
string res = response.Content.ReadAsStringAsync().Result;
if (response.IsSuccessStatusCode)
{
JObject objGPS = JObject.Parse(res);
if (objGPS.HasValues)
{
User_Id = (int)objGPS["id"];
User_Token = (string)objGPS["token"]; ---> token empty
}
}
}
It's empty because you haven't set it.
@PrimTek Can you please share your C# code. I am trying to use cookies in c# since quite a long time but still failed.
@Anton Tananaev how do I use token to get list of devices. I see no option in C# library generated through swagger.
List<Device> DevicesGet (bool? all, int? userId, int? id, string uniqueId);
This is the method in DefaultApi class. I see no option for token here.
You need to create a session using token and then use that session to issue other requests (e.g. get device list).
How do I do that in C# and Android?
How to get devices using basic auth?
Please provide a sample code snippet.
I don't have a sample, but I'm sure there are plenty of samples online on how to use basic auth. Probably you can find some on StackOverflow.
Traccar API login uses basicAuth ..
I use C# codes below, why it always return OK although I use wrong password?
string url = "http://xxxxxxxxxxxxxxxxxxxxx:8082"; var byteArray = Encoding.ASCII.GetBytes(email + ":" + password); var client = new HttpClient(); client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json"); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); var response = client.GetAsync(url).Result; HttpStatusCode statusCode = response.StatusCode;