> ## 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.

# Losant

> Client-mode REST API connector for a curated Losant slice: list devices and report device state

Technical Preview

# Losant

Client-mode REST API connector for a curated Losant slice: list devices and report device state.

* Hub category: **Cloud IoT**.
* Base: `https://api.losant.com`

## Template reference

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

### Auth

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

### Template parameters

| Placeholder | Type | Description | Required |
| - | - | - | - |
| `RouteName` | string | Name of the Losant connector | no |
| `BaseUrl` | string | Losant base URL without trailing slash (e.g. [https://api.losant.com](https://api.losant.com)) | yes |

`BASE_ADDRESS` default: `https://api.losant.com`.

### Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `Listdevices` | GET | `/applications/{value.json.application_id}/devices` | `iot/losant/devices/list` | `iot/losant/devices/list/response` | `api_token`, `application_id` |
| `Reportdevicestate` | POST | `/applications/{value.json.application_id}/devices/{value.json.device_id}/state` | `iot/losant/devices/state` | `iot/losant/devices/state/response` | `api_token`, `application_id`, `body`, `device_id` |

### 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 LOSANT"
```

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 LosantRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://api.losant.com"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT Listdevices
        WITH SOURCE_TOPIC "iot/losant/devices/list"
        WITH DESTINATION_TOPIC "iot/losant/devices/list/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/applications/{value.json.application_id}/devices"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
    ADD EVENT Reportdevicestate
        WITH SOURCE_TOPIC "iot/losant/devices/state"
        WITH DESTINATION_TOPIC "iot/losant/devices/state/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/applications/{value.json.application_id}/devices/{value.json.device_id}/state"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
        WITH BODY "{value.json.body}"
```

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 'iot/losant/devices/list/response' &
mosquitto_pub -t 'iot/losant/devices/list' -m '{"api_token": "<api_token>", "application_id": "<application_id>"}'
```


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