Notifications -> Call external rest api

Blueocean 2 years ago

Dear All

https://www.traccar.org/notifications/

Here i see that Email, Push, SMS, Telegram and web are supported.

If i want to call an external rest api please suggest how can i achieve that.

Thanks in advance.

Anton Tananaev 2 years ago

You can use SMS option.

Blueocean 2 years ago

Sorry Anton. Can you explain a bit more as to how can i use SMS option to call external rest API.

Many thanks.

Anton Tananaev 2 years ago
Blueocean 2 years ago
<entry key='notificator.types'>web,mail,sms</entry>
<entry key='sms.http.url'>https://<externalREST-API></entry>
<entry key='sms.http.authorization'>TOKEN</entry>
<entry key='sms.http.template'>
    {
        "to": "{phone}",
        "message": "{message}"
    }
</entry>

Hi Anton,

This is the traccar.xml that i need to modify right?

Also where can i modify the content of "message" value, so that i can include notification object details + geofence details.

Many thanks

Anton Tananaev 2 years ago

Are you sure you want a notification and not event forwarding?

Blueocean 2 years ago

Can you kindly give little more details of you above suggestion.

Sorry Anton for asking too many questions.

Many thanks.

Anton Tananaev 2 years ago

We have an option to forward event data to a webhook in JSON format. That sounds like what you're looking for. See configuration documentation for more info.

Blueocean 2 years ago

Thanks Anton.

I found this, hope this is the one you are referring to.

Can i pass authtoken in this because the external rest api server expects authtoken in the header. Hope i can add token like this .... <entry key="event.forward.header">Authorization: Bearer Token</entry>....

Config snippet

<!-- event forwarding -->
<entry key="event.forward.enable">true</entry>
<entry key='event.forward.url'>http://127.0.0.1:8840/evpos</entry>
<!-- <entry key='event.forward.header'>
         X-myheader: blabla
	 Y-another: hello
     </entry> -->
Blueocean 2 years ago

Kindly ignore the above message.

Please confirm if the below config is ok, i want to just forward "geofence entered" events to external server....

    <entry key='event.forward.enable'>true</entry>
    <entry key='event.forward.url'>http://127.0.0.1:8099</entry>
    <entry key='event.forward.header'>content-type: application/json</entry>
    <entry key="event.forward.header">Authorization: Bearer Token</entry>

    <entry key='web.timeout'>900000</entry>

    <entry key='event.geofenceHandler'>true</entry>
    <entry key='event.alertHandler'>true</entry>
Anton Tananaev 2 years ago

First of all, please make sure you only use parameters from here:

https://www.traccar.org/configuration-file/

Also, it's not possible to filter forwarded events. You have to filter on your receiving end.