Assign a device to read only user from admin throw null reference exception

Alaa Lahama year ago

Hello,
I am trying to assign a device to a specific user using the permission API using an admin auth, but it throws an exception

Cannot invoke "java.util.LinkedHashMap.keySet()" because "entity" is null - NullPointerException (PermissionsResource: 58 < *: 69 < *: 87 < ...)

The same exception occurs when using MySQL InnoDb (I checked foreign keys as suggested on other threads) and the default database engine H2

The http request from postman:

POST /api/permissions?userId=9&deviceId=1 HTTP/1.1 Host: localhost:3000 Content-Type: application/json Authorization: Basic YWRtaW46YWRtaW4=

I also checked the user id and device id from the database.
Another note when I do the request from PHP Laravel the exception is different

Cannot invoke "java.lang.Class.getSimpleName()" because "ownerClass" is null - NullPointerException (Permission:85 < *:97 < DatabaseStorage:161 < PermissionsResource:73 < ...)

If my request is wrong can you please point it out,I read the API documentation didn't find detailed description
The documentation I am reading: https://www.traccar.org/api-reference/#tag/Permissions/paths/~1permissions/post

Anton Tananaeva year ago

As the documentation says and shows in the example, the data should be in JSON format, not query parameters like you have in your request.

Can you please share why you decided to use query parameters.

Alaa Lahama year ago

Ah sorry I forgot about that in the PHP I am using JSON format that is why the exception is different, I tried it on postman last minute before I raise an issue so I make sure it's not a backend problem form me.

I just tried to create a new device from admin and assign to user using postman and permissions API and it worked, so I might be missing something in my backend code, or the problem from the device I am creating using the API also.

I will try it out again and replay here.

Thanks for help