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

# Kepware Iot Gateway

> Client-mode REST API connectors for PTC Kepware Server (KEPServerEX, ThingWorx Kepware Server, Kepware Edge): read server about and health, list channels, devices, tag groups and tags, create, update and delete tags through the Configuration API, read the event log, and browse, read and write live tag values through the IoT Gateway REST server

Technical Preview

## Overview

Client-mode REST API connectors for PTC Kepware Server (KEPServerEX, ThingWorx Kepware Server, Kepware Edge): read server about and health, list channels, devices, tag groups and tags, create, update and delete tags through the Configuration API, read the event log, and browse, read and write live tag values through the IoT Gateway REST server.

This is one of the templates in the Kepware (PTC KEPServerEX, ThingWorx Kepware Server, Kepware+) REST API app (`kepware`). Deploy it alongside the other connectors of that app when they depend on each other (for example a token connector plus an API connector).

## Auth

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

## Template parameters

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

`BASE_ADDRESS` default: `https://YOUR_KEPWARE_HOST:39320`.

## Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `IotgwBrowse` | GET | `/iotgateway/browse` | `historian/kepware/iotgw-tag/browse` | `historian/kepware/iotgw-tag/browse/response` | `authorization` |
| `IotgwRead` | GET | `/iotgateway/read?ids={value.json.ids}` | `historian/kepware/iotgw-value/get` | `historian/kepware/iotgw-value/get/response` | `authorization`, `ids` |
| `IotgwReadMany` | POST | `/iotgateway/read` | `historian/kepware/iotgw-value/read` | `historian/kepware/iotgw-value/read/response` | `authorization`, `body` |
| `IotgwWrite` | POST | `/iotgateway/write` | `historian/kepware/iotgw-value/write` | `historian/kepware/iotgw-value/write/response` | `authorization`, `body` |

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

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 KepwareIotGateway WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://YOUR_KEPWARE_HOST:39320"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '30'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT IotgwBrowse
        WITH SOURCE_TOPIC "historian/kepware/iotgw-tag/browse"
        WITH DESTINATION_TOPIC "historian/kepware/iotgw-tag/browse/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/iotgateway/browse"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
    ADD EVENT IotgwRead
        WITH SOURCE_TOPIC "historian/kepware/iotgw-value/get"
        WITH DESTINATION_TOPIC "historian/kepware/iotgw-value/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/iotgateway/read?ids={value.json.ids}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
    ADD EVENT IotgwReadMany
        WITH SOURCE_TOPIC "historian/kepware/iotgw-value/read"
        WITH DESTINATION_TOPIC "historian/kepware/iotgw-value/read/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/iotgateway/read"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "{value.json.authorization}"
        WITH BODY "{value.json.body}"
    ADD EVENT IotgwWrite
        WITH SOURCE_TOPIC "historian/kepware/iotgw-value/write"
        WITH DESTINATION_TOPIC "historian/kepware/iotgw-value/write/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/iotgateway/write"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "{value.json.authorization}"
        WITH BODY "{value.json.body}"
```

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

## Usage example

Call `IotgwBrowse` 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 'historian/kepware/iotgw-tag/browse/response' &
mosquitto_pub -t 'historian/kepware/iotgw-tag/browse' -m '{"authorization": "<authorization>"}'
```

## Related

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


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