Traccar API get All User

Developer 8 years ago

I have success Login and get devices, but i have problem when get all uses, this my script:

  function getUsers() {
                $.ajax({
                    url: 'http://localhost:8089/api/users/',
                    dataType: 'json',                    
                    type: 'get',
                    data: {userId:user_id},
                    xhrFields: {
                        withCredentials: true
                    },                   
                    success: function (result) {
                        console.log(result);
                    }
                })
            }

but i get response:

Admin or manager access required - SecurityException (UserResource:61 < ...)

what wrong?

Anton Tananaev 8 years ago

I think the error message is pretty self-explanatory.

Developer 8 years ago

yes, but i have login user admin password admin... and should not give me error

Anton Tananaev 8 years ago

If you get the error, it means that you haven't.

Developer 8 years ago

i wonder, iam using admin user when call api/devices give me list all device, but call api/users give me error

below is log:

Login response,

{"id":1,"attributes":{},"name":"admin","login":null,"email":"admin","phone":null,"readonly":false,"administrator":true,"map":null,"latitude":0.0,"longitude":0.0,"zoom":0,"twelveHourFormat":false,"coordinateFormat":null,"disabled":false,"expirationTime":null,"deviceLimit":-1,"userLimit":0,"deviceReadonly":false,"token":null,"limitCommands":false,"poiLayer":null,"password":null}

call api/devices/

[{"id":1,"attributes":{},"groupId":0,"name":"DEMO","uniqueId":"351608082420022","status":"offline","lastUpdate":"2018-06-12T15:44:34.000+0000","positionId":0,"geofenceIds":[],"phone":"","model":"","contact":"","category":null,"disabled":false},{"id":2,"attributes":{},"groupId":0,"name":"GT02D SETTING","uniqueId":"358899050841710","status":"offline","lastUpdate":"2018-06-13T08:44:19.000+0000","positionId":530,"geofenceIds":[],"phone":"","model":"","contact":"","category":null,"disabled":false},{"id":3,"attributes":{},"groupId":0,"name":"FRMI","uniqueId":"352887072433620","status":"offline","lastUpdate":null,"positionId":0,"geofenceIds":[],"phone":"","model":"","contact":"","category":null,"disabled":false},{"id":4,"attributes":{},"groupId":0,"name":"B1891FOZ","uniqueId":"358899055785383","status":"offline","lastUpdate":"2018-06-20T03:18:49.000+0000","positionId":660,"geofenceIds":[],"phone":"","model":"","contact":"","category":null,"disabled":false},{"id":5,"attributes":{},"groupId":0,"name":"NOPOL ADMIN","uniqueId":"233333","status":"offline","lastUpdate":null,"positionId":0,"geofenceIds":[],"phone":"","model":"","contact":"","category":null,"disabled":false}]

call api/users

Admin or manager access required - SecurityException (UserResource:61 < ...)
Anton Tananaev 8 years ago

What does GET /api/session return?

Developer 8 years ago

HTTP 404 Not Found - WebApplicationException (SessionResource:95 < ...

function getLogin() {
                $.ajax({
                    url: 'http://localhost:8089/api/session/',
                    dataType: 'json',
                    type: 'get',
                    success: function (result) {
                        console.log(result);
                    }
                })
            }

{"id":1,"attributes":{},"name":"admin","login":null,"email":"admin","phone":null,"readonly":false,"administrator":true,"map":null,"latitude":0.0,"longitude":0.0,"zoom":0,"twelveHourFormat":false,"coordinateFormat":null,"disabled":false,"expirationTime":null,"deviceLimit":-1,"userLimit":0,"deviceReadonly":false,"token":null,"limitCommands":false,"poiLayer":null,"password":null}

function getLogin() {
                $.ajax({
                    url: 'http://localhost:8089/api/session/',
                    dataType: 'json',
                    type: 'get',
<span style="color:red">
                    xhrFields: {
                        withCredentials: true
                    },
</span>
                    success: function (result) {
                        console.log(result);
                    }
                })
            }
Anton Tananaev 8 years ago

What is data: {userId:user_id} in your users request? Please carefully read documentation and don't try to guess API.

Developer 8 years ago

I just remove any parameters data: {userId:user_id}, and not solve this problem

Developer 8 years ago

Problem solve i get all users...

jaimzj 8 years ago

@xtracker would you be willing to share the ajax example of login? my email is jamejo (at) gmail (dot) com

Developer 8 years ago
$.ajax({
                    url: path + '/api/session/',
                    dataType: 'json',
                    type: 'post',
                    data: data,
                    success: function (result) {
                        console.log(result);
                        window.location = 'index.html';
                    }
                });
AsifB 7 years ago

When I executed this http://n.n.n.n:8082/api/users from postman, I got only 3 users. I could not find any parameters in the documentation which would get me the full list of users.

AsifB 7 years ago

API is working fine. There was an issue with the way some of the User IDs were created. So they were not being listed. I have fixed the IDs. Now it is working fine.