How to forward traccar's events to Web API?

Don4 years ago

Hello,

I ran traccar 4.10 on CentOS 7 (x64), I want to forward traccar events (geofencing, odometer, speed, etc) to our webhooks API (https://mydomain.com/api/webhooks)

I read from https://www.traccar.org/configuration-file/

there are some info like below but it does not clear for me, where can I find the example of them?
I also read /opt/traccar/conf/default.xml but again I did not find a clue for this.

questions:

  • how to forward traccar's events to external API (ie. our webhooks API)
  • where can I find the tech doc, article or config example for doing this?

many thanks

Don

forward.enable config
Enable positions forwarding to other web server.

forward.url config
URL to forward positions. Data is passed through URL parameters. For example, {uniqueId} for device identifier, {latitude} and {longitude} for coordinates.

forward.json config
Boolean value to enable forwarding in JSON format.

event.forward.enable config
Enable events forwarding to other web server.

event.forward.url config
URL to forward events.

event.forward.header config
Additional HTTP header, can be used for authorization.
Anton Tananaev4 years ago

I'm sure you can find some usage examples on the forum.

Don4 years ago

Hi Anton,

Thank you, you are right!.. I found it but I did not find a way if the Web API requires authorization header (like API-Key and API-Secret)..
any suggestion?

Don4 years ago

this is my last try, I put this in traccar.xml .. I expect to receive notification event (like, geofence enter, exit, device status on, off, unknown etc)..
what I have received is as follow:

{"position":{"id":0,"attributes":{"batteryLevel":77.0,"distance":2.9,"totalDistance":24547.58,"motion":false},"deviceId":1,"type":null,"protocol":"osmand","serverTime":"2020-08-01T08:43:58.222+0000","deviceTime":"2020-08-01T08:43:48.000+0000","fixTime":"2020-08-01T08:43:48.000+0000","outdated":false,"valid":true,"latitude":-6.236127,"longitude":106.654282,"altitude":38.0667610168457,"speed":0.0,"course":0.0,"address":"Tangerang Selatan, Banten, ID","accuracy":65.0,"network":null},"device":{"id":1,"attributes":{},"groupId":0,"name":"test@iOS","uniqueId":"264937","status":"online","lastUpdate":"2020-08-01T08:43:58.228+0000","positionId":66,"geofenceIds":[],"phone":"","model":"","contact":"","category":null,"disabled":false}} 

traccar.xml

<entry key='forward.enable'>true</entry>
<entry key='forward.url'>https://mydomain.com/api/mywebhooks</entry>
<entry key='forward.json'>true</entry>

<entry key="event.forward.enable">true</entry>
<entry key='event.forward.url'>https://mydomain.com/api/mywebhooks</entry>

Please help

Thanks a lot in advance

Don

Anton Tananaev4 years ago

You enabled both positions and events forwarding, so it seems like you get exactly what you configured.

Don4 years ago

Sorry, I don’t understand what do you mean?
I expect to receive position and also notification event (like, geofence enter, exit, device status on, off, unknown etc) by forwarding them to our web API.

What I missed?

Anton Tananaev4 years ago

You are receiving positions. I don't really understand what the issue is.

Don4 years ago

I also expect to receive notification info through API.

Other than that, my device is linked with geofence but it shows geofenceIds":[]

My understanding is geofenceids is a list of devices that currently in geofence area, so mine should also listed there. Cmiiw

Anton Tananaev4 years ago

geofenceids is a list of devices that currently in geofence area

That's incorrect. It's a list of geofences, not devices.

Don4 years ago

Anton, thank you for your correction, so it is the id of geofence but it should not be empty, I was in that geofence area just now but it shows “geofenceIds":[]

Don4 years ago

By the way, where can I find the geofence id in the geofence setup page? It only shows Name and Description

Anton Tananaev4 years ago
  1. If you have multiple issues/questions, I would recommend to create separate threads. But make sure you do a research first before asking.
  2. If you have any issues, please provide all the details for us to identify the problem. So far you haven't really provide any details that could help to identify the root causes.
Don4 years ago

Anton
Well noted and thank you