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

# Rhize Api

> LoT connector for the Rhize ISA-95 data hub GraphQL API: record job responses and equipment actuals, query material lots and KPIs, and start BPMN workflows

Technical Preview

## Overview

Client-mode REST API connector for Rhize, the ISA-95 manufacturing data hub: record job responses and equipment actuals from production topics, add and update equipment, query equipment, job responses, material lots, data sources, KPIs and the audit log, and start BPMN workflows, through the Rhize GraphQL API with Keycloak tokens.

This is one of the templates in the Rhize (ISA-95 manufacturing data hub) REST API app (`rhize`). 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

Keycloak OpenID Connect. RhizeAuth GetAccessToken (client\_credentials) or GetPasswordToken (password grant) returns a JWT (docs example expires\_in 28800); publish authorization 'Bearer \<access\_token>' on every RhizeApi event. Hub secrets RHIZE\_REALM, RHIZE\_CLIENT\_ID, RHIZE\_CLIENT\_SECRET (+ RHIZE\_USERNAME / RHIZE\_PASSWORD for the password grant).

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

## Template parameters

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

`BASE_ADDRESS` default: `https://YOUR_RHIZE_HOST`.

## Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `QueryEquipment` | POST | `/graphql` | `historian/rhize/equipment/query` | `historian/rhize/equipment/query/response` | `authorization`, `request` |
| `GetEquipment` | POST | `/graphql` | `historian/rhize/equipment/get` | `historian/rhize/equipment/get/response` | `authorization`, `request` |
| `AggregateEquipment` | POST | `/graphql` | `historian/rhize/equipment/aggregate` | `historian/rhize/equipment/aggregate/response` | `authorization`, `request` |
| `AddEquipment` | POST | `/graphql` | `historian/rhize/equipment/add` | `historian/rhize/equipment/add/response` | `authorization`, `request` |
| `UpdateEquipmentVersion` | POST | `/graphql` | `historian/rhize/equipment-version/update` | `historian/rhize/equipment-version/update/response` | `authorization`, `request` |
| `QueryJobResponse` | POST | `/graphql` | `historian/rhize/job-response/query` | `historian/rhize/job-response/query/response` | `authorization`, `request` |
| `AddJobResponse` | POST | `/graphql` | `historian/rhize/job-response/add` | `historian/rhize/job-response/add/response` | `authorization`, `request` |
| `AddEquipmentActual` | POST | `/graphql` | `historian/rhize/equipment-actual/add` | `historian/rhize/equipment-actual/add/response` | `authorization`, `request` |
| `QueryMaterialLot` | POST | `/graphql` | `historian/rhize/material-lot/query` | `historian/rhize/material-lot/query/response` | `authorization`, `request` |
| `QueryDataSource` | POST | `/graphql` | `historian/rhize/data-source/query` | `historian/rhize/data-source/query/response` | `authorization`, `request` |
| `QueryKpi` | POST | `/graphql` | `historian/rhize/kpi/query` | `historian/rhize/kpi/query/response` | `authorization`, `request` |
| `QueryAuditLog` | POST | `/graphql` | `historian/rhize/audit-log/query` | `historian/rhize/audit-log/query/response` | `authorization`, `request` |
| `StartWorkflow` | POST | `/graphql` | `historian/rhize/workflow/start` | `historian/rhize/workflow/start/response` | `authorization`, `request` |
| `RunWorkflowSync` | POST | `/graphql` | `historian/rhize/workflow/run` | `historian/rhize/workflow/run/response` | `authorization`, `request` |

## Deploy

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

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

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

```lot theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
DEFINE CONNECTOR RhizeApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://YOUR_RHIZE_HOST"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '30'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT QueryEquipment
        WITH SOURCE_TOPIC "historian/rhize/equipment/query"
        WITH DESTINATION_TOPIC "historian/rhize/equipment/query/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/graphql"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.request}"
    ADD EVENT GetEquipment
        WITH SOURCE_TOPIC "historian/rhize/equipment/get"
        WITH DESTINATION_TOPIC "historian/rhize/equipment/get/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/graphql"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.request}"
    ADD EVENT AggregateEquipment
        WITH SOURCE_TOPIC "historian/rhize/equipment/aggregate"
        WITH DESTINATION_TOPIC "historian/rhize/equipment/aggregate/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/graphql"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.request}"
    ADD EVENT AddEquipment
        WITH SOURCE_TOPIC "historian/rhize/equipment/add"
        WITH DESTINATION_TOPIC "historian/rhize/equipment/add/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/graphql"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.request}"
    ADD EVENT UpdateEquipmentVersion
        WITH SOURCE_TOPIC "historian/rhize/equipment-version/update"
        WITH DESTINATION_TOPIC "historian/rhize/equipment-version/update/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/graphql"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.request}"
    ADD EVENT QueryJobResponse
        WITH SOURCE_TOPIC "historian/rhize/job-response/query"
        WITH DESTINATION_TOPIC "historian/rhize/job-response/query/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/graphql"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.request}"
    ADD EVENT AddJobResponse
        WITH SOURCE_TOPIC "historian/rhize/job-response/add"
        WITH DESTINATION_TOPIC "historian/rhize/job-response/add/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/graphql"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.request}"
    ADD EVENT AddEquipmentActual
        WITH SOURCE_TOPIC "historian/rhize/equipment-actual/add"
        WITH DESTINATION_TOPIC "historian/rhize/equipment-actual/add/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/graphql"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.request}"
    ADD EVENT QueryMaterialLot
        WITH SOURCE_TOPIC "historian/rhize/material-lot/query"
        WITH DESTINATION_TOPIC "historian/rhize/material-lot/query/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/graphql"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.request}"
    ADD EVENT QueryDataSource
        WITH SOURCE_TOPIC "historian/rhize/data-source/query"
        WITH DESTINATION_TOPIC "historian/rhize/data-source/query/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/graphql"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.request}"
    ADD EVENT QueryKpi
        WITH SOURCE_TOPIC "historian/rhize/kpi/query"
        WITH DESTINATION_TOPIC "historian/rhize/kpi/query/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/graphql"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.request}"
    ADD EVENT QueryAuditLog
        WITH SOURCE_TOPIC "historian/rhize/audit-log/query"
        WITH DESTINATION_TOPIC "historian/rhize/audit-log/query/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/graphql"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.request}"
    ADD EVENT StartWorkflow
        WITH SOURCE_TOPIC "historian/rhize/workflow/start"
        WITH DESTINATION_TOPIC "historian/rhize/workflow/start/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/graphql"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.request}"
    ADD EVENT RunWorkflowSync
        WITH SOURCE_TOPIC "historian/rhize/workflow/run"
        WITH DESTINATION_TOPIC "historian/rhize/workflow/run/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/graphql"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "{value.json.authorization}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.request}"
```

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

## Usage example

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

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
mosquitto_sub -t 'historian/rhize/equipment/query/response' &
mosquitto_pub -t 'historian/rhize/equipment/query' -m '{"authorization": "<authorization>", "request": "<request>"}'
```

## Related

* [REST API Connectors](https://docs.coreflux.org/v2.22/lot-language/routes/rest-api-routes.md)
* [REST API Apps catalog](https://docs.coreflux.org/v2.22/lot-language/routes/rest-api-apps.md)


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