api problem with groupID

Fred5 years ago

Hello,
Traccar v4.6 standalone.
Maybe I don't understand, but I cannot use api with groupId

GET groups

[
  {
    "id": 1,
    "attributes": {},
    "groupId": 0,
    "name": "groupe1"
  }
]

GET devices?id=2

[
  {
    "id": 2,
    "attributes": {},
    "groupId": 0,
    "name": "iPhone",
    "uniqueId": "iphone-fred",
    "status": "online",
    "lastUpdate": "2020-06-16T09:44:26.444+0000",
    "positionId": 4132,
    "geofenceIds": [],
    "phone": "",
    "model": "",
    "contact": "",
    "category": "person",
    "disabled": false
  }
]
curl -X POST -H "Content-Type: application/json" -H "Authorization: Basic xxxxxxxxxxxxxxx" -d '{ "groupId": "0", "deviceId": "2" }' "https://xxxxxxxxxxxxx/api/permissions"
Table "TC_GROUP_DEVICE" not found; SQL statement:
INSERT INTO tc_group_device (groupId, deviceId) VALUES (?, ?) [42102-199] - JdbcSQLSyntaxErrorException (... < QueryBuilder:65 < *:135 < DataManager:438 < PermissionsResource:63 63 < ...)

Or

curl -X POST -H "Content-Type: application/json" -H "Authorization: Basic xxxxxxxxxxxxxxx" -d '{ "userId": "33", "groupId": "0" }' "https://xxxxxxxxxxxxx/api/permissions"
Referential integrity constraint violation: "FK_USER_GROUP_GROUPID: PUBLIC.TC_USER_GROUP FOREIGN KEY(GROUPID) REFERENCES PUBLIC.TC_GROUPS(ID) (0)"; SQL statement:
INSERT INTO tc_user_group (userId, groupId) VALUES (?, ?) [23506-199] - JdbcSQLIntegrityConstraintViolationException (... < QueryBuilder:480 < DataManager:441 < PermissionsResource: 63 < ...)

but

curl -X POST -H "Content-Type: application/json" -H "Authorization: Basic xxxxxxxxxxxxxxx" -d '{ "userId": "33", "deviceId": "2" }' "https://xxxxxxxxxxxxxxx/api/permissions"

WORKS!

I see this post:
[topic apipermissions]:(https://www.traccar.org/forums/topic/apipermissions/)

My traccar not use an database mysql.

Thanks

Anton Tananaev5 years ago

You are using invalid group id. In your example group id is 1 not 0:

"id": 1

The groupId parameter in group model refers to parent group of the group, which is not set in your case.

Fred5 years ago

Ok thanks,

sorry, but:

curl -X POST -H "Content-Type: application/json" -H "Authorization: Basic xxxxxxxxxxxxxxx" -d '{"deviceId": "2", "groupId": "1" }' "https://xxxxxxxxxxxxxxx/api/permissions"
Table "TC_DEVICE_GROUP" not found; SQL statement:
INSERT INTO tc_device_group (deviceId, groupId) VALUES (?, ?) [42102-199] - JdbcSQLSyntaxErrorException (... < QueryBuilder:65 < *:135 < DataManager:438 < PermissionsResource:63

or

curl -X POST -H "Content-Type: application/json" -H "Authorization: Basic xxxxxxxxxxxxxxx" -d '{ "groupId": "1", "device": "2" }' "https://xxxxxxxxxxxxxxx/api/permissions"
Table "TC_GROUP_DEVICE" not found; SQL statement:
INSERT INTO tc_group_device (groupId, deviceId) VALUES (?, ?) [42102-199] - JdbcSQLSyntaxErrorException (... < QueryBuilder:65 < *:135 < DataManager:438 < PermissionsResource:63 < ...)
Anton Tananaev5 years ago

Now I'm not sure what the issue is. Check database to see if id is still valid. One thing I don't understand is why you are trying to send numeric values as strings.

Fred5 years ago

Hello,

I reinstall Traccar with docker and mariadb on another host.

I try again curl api commande and I have the same error.

Table 'traccar.tc_group_device' doesn't exist - SQLSyntaxErrorException (... < QueryBuilder:480 < DataManager:441 < PermissionsResource:63 < ...)

And effectively, I don't have the tc_group_device in database.

How I can create it with rights options?
Thanks

Anton Tananaev5 years ago

If you don't have a table, then it means something was wrong with migration. It can indicate much bigger problems. You need to find the root cause.

Fred5 years ago

Thanks,

New traccar from scratch. No migration.

Can you or someone, just said to me the type of table of tc_group_device. To create.
Thanks

Anton Tananaev5 years ago

Migration is done even on clean installation. It initializes the database.

Fred5 years ago

Hello,

I try to find something about git grep tc_group_device in code, but nothing.

https://github.com/traccar/traccar/blob/master/schema/changelog-4.0-clean.xml
Don't find tc_group_device

git grep tc_group_device
Don't find tc_group_device

Maybe there is no table tc_group_device by default?
Thanks

Anton Tananaev5 years ago

Just checked. Correct, such table doesn't exist. Sounds like you are using wrong API requests.

Fred5 years ago

Thanks
Simple question.
Is it possible to link device to group?

curl -X POST -H "Content-Type: application/json" -H "Authorization: Basic xxxxxxxxxxxxxxx" -d '{ "groupId": 0, "deviceId": 2 }' "https://xxxxxxxxxxxxx/api/permissions"
Anton Tananaev5 years ago

Yes, but that's not how you do it. There is a groupId field in the device model.

Fred5 years ago

OK,

I created table like this:
create table tc_group_device (groupid int, deviceId int);

And curl this:

curl -X POST -H "Content-Type: application/json" -H "Authorization: Basic xxxxxxxxxxxxxxx" -d '{ "groupId": 0, "deviceId": 1 }' "https://xxxxxxxxxxxxx/api/permissions"

And when I request GET by api the device, groupid appears!

Is it correct?

Thanks

Anton Tananaev5 years ago

It is incorrect.