Forward url

arnold2 years ago

I am trying to forward traccar gps data to my callback url from config file like below:

<entry key='event.forward.enable'>true</entry>-->
<entry key='event.forward.url'>http://192.168.1.6/traccar?id={uniqueId}&amp;deviceId={deviceId}&amp;valid={valid}&amp;fixTime={fixTime}&amp;deviceTime={deviceTime}&amp;protocol={protocol}&amp;name={name}&amp;latitude={latitude}&amp;longitude={longitude}&amp;altitude={altitude}&amp;speed={speed}&amp;attributes={attributes}</entry>

And I get the following error

INFO: [Tc2479c42] error - The template variable 'uniqueId' has no value - IllegalArgumentException (... < EventForwarderJson:41 < NotificationManager:141 < *:83 < *:155 < ConnectionManager:247 < ...)
Anton Tananaev2 years ago

Where did you get this configuration from?

arnold2 years ago

Hi Anton,
I found an example in one forum post and tried to send custom data to my url
https://www.traccar.org/forums/topic/are-there-server-hooks/#post-1934

If I do not specify parameters in url it forward data but not device attributes and coordinates

Anton Tananaev2 years ago

The configuration parameters are completely different in that post.

arnold2 years ago

Here is my config file

 <entry key='forward.enable'>true</entry>
 <entry key='forward.url'>http://192.168.89.239:3001/traccar/Data?id={uniqueId}</entry>

and the log

 WARN: Position forwarding failed: 0 pending - HTTP code 404 - RuntimeException (PositionForwarderUrl:74 < *:67 < ...)
Anton Tananaev2 years ago

As you hopefully can see, your URL is returning error 404.

arnold2 years ago

Hi Anton,

with this configuration

 <entry key='forward.enable'>true</entry>
 <entry key='forward.url'>http://192.168.89.239:3001/traccar/Data</entry>

I am able to get this data, but when I enter parameters like id, lat, lon, or any other I get:

error - The template variable 'lat' has no value - IllegalArgumentException (... < EventForwarderJson:41 < NotificationManager:141 < *:83 < *:155 < ConnectionManager:247 < ...)
{
  event: {
    id: 9495,
    attributes: {},
    deviceId: 5,
    type: 'deviceOnline',
    eventTime: '2024-04-22T07:21:25.966+00:00',
    positionId: 0,
    geofenceId: 0,
    maintenanceId: 0
  },
  device: {
    id: 5,
    attributes: {},
    groupId: 0,
    calendarId: 0,
    name: 'E-mak',
    uniqueId: '864636061378788',
    status: 'online',
    lastUpdate: '2024-04-22T07:21:25.966+00:00',
    positionId: 90419,
    phone: null,
    model: null,
    contact: null,
    category: null,
    disabled: false,
    expirationTime: null
  }
}
Anton Tananaev2 years ago

This is not your configuration. The error is with event forwarding, which means you provided incorrect information.

arnold2 years ago

This is config.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE properties SYSTEM 'http://java.sun.com/dtd/properties.dtd'>
<properties>
      <entry key="config.default">./conf/default.xml</entry>
      <entry key='database.driver'>com.mysql.cj.jdbc.Driver</entry>
      <entry key='database.url'>jdbc:mysql://localhost/traccar?serverTimezone=UTC&amp;useSSL=false&amp;allowMultiQueries=true&amp;autoReconnect=true&amp;useUnicode=yes&amp;characterEncoding=UTF-8&amp;sessionVariables=sql_mode=''</entry>
      <entry key='database.user'>*****</entry>
      <entry key='database.password'>*********</entry>
      <entry key='server.port'>5055</entry>
      <entry key='forward.enable'>true</entry>
      <entry key='forward.url'>http://192.168.1.39:3000/traccar?id={uniqueId}&amp;protocol={protocol}&amp;name={name}&amp;latitude={latitude}&amp;longitude={longitude}&amp;altitude={altitude}&amp;speed={speed}&amp;attributes={attributes}</entry>
</properties>

and the webhook is a simple js function to parse url and body. I would appreciate your suggestion.