Traccar API 500 Error on getting positions

Obaid Khan7 years ago

Please tell me is this a valid http request from getting past positions

http://track.gatsan.com:80/api/positions?from=2018-03-18T18:30:00Z&to=2018-03-20T18:30:00Z
Anton Tananaev7 years ago

That's a URL, not a request. And even the URL is not correct. There is no device or group.

Obaid Khan7 years ago

Please add time request to this code. That would be really helpful

private void test()
        {
            string url = "http://track.gatsan.com:80/api/positions";

            var pairs = new List<KeyValuePair<string, string>> { };

            
            var byteArray = Encoding.ASCII.GetBytes("admin" + ":" + "admin");

            var client = new HttpClient();
            client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            
            var content = new FormUrlEncodedContent(pairs);

            var response = client.GetAsync(url).Result;
            HttpStatusCode statusCode = response.StatusCode;

            switch (statusCode)
            {
                case HttpStatusCode.OK:
                    {
                        response.EnsureSuccessStatusCode();
                        string res = response.Content.ReadAsStringAsync().Result;
                        if (response.IsSuccessStatusCode)
                        {
                            JArray rows = JArray.Parse(res);
                            if (rows.HasValues)
                            {
                                foreach (JToken row in rows)
                                {
                                    MessageBox.Show(row.ToString());
                                }
                            }
                        }
                    }
                    break;
            }

        }