Geofence IDs not working

Kelvin Murithi5 years ago

Am using the devices endpoint to get the list of devices but the geofenceIds is empty which is wrong because I have created geofences and associated them with this device. From the web admin, the devices geofence are shown correctly, also the geofence endpoint with the device filter shows this device has geofences associated with it. What could be the issue causing the geofenceIds to be empty on the devices API but show correctly on web and geofences endpoint?

Anton Tananaev5 years ago

It's not wrong. From devices endpoint you only get geofences that the device is currently in, not all linked ones.

Kelvin Murithi5 years ago

So all geofences created automatically are linked with all devices and geofenceIds in the Device body only shows geofences the device is in. If the device is out of the area then it won't be shown. right?

Anton Tananaev5 years ago

You still need to link geofences to devices.

Kelvin Murithi5 years ago

Can you please help me in how to do that via the Rest API. Which endpoint should do this linking?

Anton Tananaev5 years ago

Check how the official web app does it.

Kelvin Murithi5 years ago

Sorry for all this. But I would like to use the APIs directly. am not aware of how to check the logic the web app uses

My devices list. device id 3
My Devices

Geofences list with device id 3 query
Does this show they are linked with this device?
My Devices

Usman Khan2 years ago

Hi Anton Tananaev,

I am also facing similar issue:

  • I create a permission link between deviceId and geofenceId with linker Api which respond status 204
  • Then i update the device object with the geofence id of which i created the link.
  • The update api Response shows that the device is updated with the geofence id , with response status 200
  • But when i fetch the same device again , the geofenceId attribute in the device object does not change.
  1. Why the update device response 200 and showing the device object updated in the response?. But when we fetch it again its is remains the same (not updated).
  2. How can we solve this issue?
Anton Tananaev2 years ago

The update api Response shows that the device is updated with the geofence id

You cannot do this. The geofence id is simply ignored on the update.

Usman Khan2 years ago

Yes Anton Tananaev,

You are right.

  • Only geofence id attribute is being ignored and I tried updating the phone attribute and it is working.
  • If the geofenced is not updating in the device then the geofence is actually useless.

Can u please guide me through why is it ignoring the geofenceid . and how can we fix that ?

Anton Tananaev2 years ago

Because it's a field that Traccar updates. You cannot update it manually. Why would you want to update it yourself?

Usman Khan2 years ago

So, We have this project with some features and it's really crucial for us to update the geofence id in order to connect like 1000 devices at the same time with the geofence, and changing it in future as well, because doing it manually one by one will take long time.

Anton Tananaev2 years ago

I feel like you are working based off a wrong assumption. You don't need to change that field to link geofences to devices. You only need to do the permission linking.

Usman Khan2 years ago

you mean only permission linking can connect the device to the geofence, without updating the geofenceId field in the Device object.

Anton Tananaev2 years ago

Yes. Not just can, but that's the only way it should work.

Also, speaking about 1000 devices, you should probably use groups if you need to link each geofence to so many devices. Link it to a group instead.