> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Traccar (open-source GPS server) REST API

> Client-mode REST API connector for Traccar positions, devices, and connector reports

Technical Preview

## Overview

Client-mode REST API connector for Traccar positions, devices, and connector reports. `BASE_ADDRESS` defaults to `https://YOUR_TRACCAR_HOST:8082`. Auth: **Basic or Bearer session token**. Pass secrets only at runtime via MQTT JSON placeholders or Hub `GET SECRET` — never commit real credentials.

## Auth

Basic or Bearer session token. Prefer Hub secrets / `GET SECRET`. Never hard-code tokens into the `.lot`.

## Basic Syntax

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}

DEFINE ROUTE TraccarRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://YOUR_TRACCAR_HOST:8082"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '30'
        WITH DEFAULT_CONTENT_TYPE "application/json"
        # Auth: Authorization Bearer {value.json.api_token} — prefer Hub secrets / GET SECRET.
        # Optional Basic: WITH USERNAME "YOUR_USER" / WITH PASSWORD GET SECRET "APP_PASSWORD"
    ADD EVENT Listdevices
        WITH SOURCE_TOPIC "integrations/traccar/request/Listdevices"
        WITH DESTINATION_TOPIC "integrations/traccar/response/Listdevices"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/devices"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
    ADD EVENT Getdevice
        WITH SOURCE_TOPIC "integrations/traccar/request/Getdevice"
        WITH DESTINATION_TOPIC "integrations/traccar/response/Getdevice"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/devices/{value.json.id}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
    ADD EVENT Listpositions
        WITH SOURCE_TOPIC "integrations/traccar/request/Listpositions"
        WITH DESTINATION_TOPIC "integrations/traccar/response/Listpositions"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/positions"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
    ADD EVENT Listpositionsbydevice
    # ... additional EVENTs in package .lot ...
```

## MQTT topics

Request topics under `integrations/traccar/request/...`; responses on `integrations/traccar/response/...`.

## Template reference

Generated from the shipped broker template `traccar` (`-routeCode TRACCAR`). It lists every event the template defines.

### Auth

Basic or Bearer session token

Auth headers used by the template: `Authorization: Bearer {value.json.api_token}`.

### Template parameters

| Placeholder | Type | Description | Required |
| - | - | - | - |
| `RouteName` | string | Name of the Traccar connector | no |
| `BaseUrl` | string | Traccar base URL without trailing slash (e.g. https\://YOUR\_TRACCAR\_HOST:8082) | yes |

`BASE_ADDRESS` default: `https://YOUR_TRACCAR_HOST:8082`.

### Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `Listdevices` | GET | `/api/devices` | `integrations/traccar/request/Listdevices` | `integrations/traccar/response/Listdevices` | `api_token` |
| `Getdevice` | GET | `/api/devices/{value.json.id}` | `integrations/traccar/request/Getdevice` | `integrations/traccar/response/Getdevice` | `api_token`, `id` |
| `Listpositions` | GET | `/api/positions` | `integrations/traccar/request/Listpositions` | `integrations/traccar/response/Listpositions` | `api_token` |
| `Listpositionsbydevice` | GET | `/api/positions?deviceId={value.json.deviceId}` | `integrations/traccar/request/Listpositionsbydevice` | `integrations/traccar/response/Listpositionsbydevice` | `api_token`, `deviceId` |
| `Getroutereport` | GET | `/api/reports/route?deviceId={value.json.deviceId}&from={value.json.from}&to={value.json.to}` | `integrations/traccar/request/Getroutereport` | `integrations/traccar/response/Getroutereport` | `api_token`, `deviceId`, `from`, `to` |
| `Createsession` | POST | `/api/session` | `integrations/traccar/request/Createsession` | `integrations/traccar/response/Createsession` | `api_token`, `body` |
| `Listevents` | GET | `/api/events` | `integrations/traccar/request/Listevents` | `integrations/traccar/response/Listevents` | `api_token` |
| `Listgeofences` | GET | `/api/geofences` | `integrations/traccar/request/Listgeofences` | `integrations/traccar/response/Listgeofences` | `api_token` |

### Deploy

Get the template card (JSON with `template` and `metadata`) from the broker, then deploy the connector:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_pub -t '$SYS/Coreflux/Command' -m "-routeCode TRACCAR"
```

The deployable connector from the REST API app, with `BASE_ADDRESS` already filled in:

```lot theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
DEFINE ROUTE TraccarRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://YOUR_TRACCAR_HOST:8082"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '30'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT Listdevices
        WITH SOURCE_TOPIC "integrations/traccar/request/Listdevices"
        WITH DESTINATION_TOPIC "integrations/traccar/response/Listdevices"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/devices"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
    ADD EVENT Getdevice
        WITH SOURCE_TOPIC "integrations/traccar/request/Getdevice"
        WITH DESTINATION_TOPIC "integrations/traccar/response/Getdevice"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/devices/{value.json.id}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
    ADD EVENT Listpositions
        WITH SOURCE_TOPIC "integrations/traccar/request/Listpositions"
        WITH DESTINATION_TOPIC "integrations/traccar/response/Listpositions"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/positions"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
    ADD EVENT Listpositionsbydevice
        WITH SOURCE_TOPIC "integrations/traccar/request/Listpositionsbydevice"
        WITH DESTINATION_TOPIC "integrations/traccar/response/Listpositionsbydevice"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/positions?deviceId={value.json.deviceId}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
    ADD EVENT Getroutereport
        WITH SOURCE_TOPIC "integrations/traccar/request/Getroutereport"
        WITH DESTINATION_TOPIC "integrations/traccar/response/Getroutereport"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/reports/route?deviceId={value.json.deviceId}&from={value.json.from}&to={value.json.to}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
    ADD EVENT Createsession
        WITH SOURCE_TOPIC "integrations/traccar/request/Createsession"
        WITH DESTINATION_TOPIC "integrations/traccar/response/Createsession"
        WITH METHOD "POST"
        WITH ENDPOINT "/api/session"
        WITH HEADERS
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
        WITH BODY "{value.json.body}"
    ADD EVENT Listevents
        WITH SOURCE_TOPIC "integrations/traccar/request/Listevents"
        WITH DESTINATION_TOPIC "integrations/traccar/response/Listevents"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/events"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
    ADD EVENT Listgeofences
        WITH SOURCE_TOPIC "integrations/traccar/request/Listgeofences"
        WITH DESTINATION_TOPIC "integrations/traccar/response/Listgeofences"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/geofences"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
```

Deploy it with `-addRoute` (do not include `ADD METADATA`).

### Usage example

Call `Listdevices` by publishing a JSON payload to its request topic, and read the reply on the response topic:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_sub -t 'integrations/traccar/response/Listdevices' &
mosquitto_pub -t 'integrations/traccar/request/Listdevices' -m '{"api_token": "<api_token>"}'
```

## Related

* [REST API Connectors](/latest/lot-language/routes/rest-api-routes)
* [REST API apps index](/latest/lot-language/routes/rest-api-apps)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.