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

# Bar Tender Cloud

> LoT connector for BarTender Cloud: submit print scripts, track script status and variables, and list printers from MQTT with a Bearer token

Technical Preview

## Overview

Client-mode REST API connectors for BarTender label printing: print BarTender documents with data from MQTT through the BarTender 2022+ Actions API (on-premises or BarTender Cloud) or Print Portal, follow the print script status and variables, and list printers and Print Portal libraries.

This is one of the templates in the BarTender (Seagull Scientific) label printing REST API app (`bartender-label-printing`). 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

* **BarTenderActions**: Windows authentication (Negotiate) on the REST service; not sent by the connector (reverse proxy needed, unverified)
* **BarTenderCloud**: Authorization: Bearer \{value.json.access\_token}
* **BarTenderPrintPortal**: POST /BarTender/api/v1/Authenticate \{userName,password} -> token; Authorization: Bearer \{value.json.token}
* **secret**: \["BARTENDER\_PORTAL\_USERNAME", "BARTENDER\_PORTAL\_PASSWORD"]

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

## Template parameters

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

`BASE_ADDRESS` default: `https://am1.bartendercloud.com`.

## Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `CloudSubmitScript` | POST | `/api/actions?{value.json.query}` | `mes/bartender-cloud/script/submit` | `mes/bartender-cloud/script/submit/response` | `access_token`, `body`, `query` |
| `CloudListScripts` | GET | `/api/actions?{value.json.query}` | `mes/bartender-cloud/script/list` | `mes/bartender-cloud/script/list/response` | `access_token`, `query` |
| `CloudGetScriptStatus` | GET | `/api/actions/{value.json.script_id}?{value.json.query}` | `mes/bartender-cloud/script/get` | `mes/bartender-cloud/script/get/response` | `access_token`, `query`, `script_id` |
| `CloudUpdateScript` | PATCH | `/api/actions/{value.json.script_id}` | `mes/bartender-cloud/script/update` | `mes/bartender-cloud/script/update/response` | `access_token`, `body`, `script_id` |
| `CloudListScriptVariables` | GET | `/api/actions/{value.json.script_id}/variables` | `mes/bartender-cloud/script-variable/list` | `mes/bartender-cloud/script-variable/list/response` | `access_token`, `script_id` |
| `CloudGetScriptVariable` | GET | `/api/actions/{value.json.script_id}/variables/{value.json.variable}` | `mes/bartender-cloud/script-variable/get` | `mes/bartender-cloud/script-variable/get/response` | `access_token`, `script_id`, `variable` |
| `CloudListPrinters` | GET | `/api/devices/printers?{value.json.query}` | `mes/bartender-cloud/printer/list` | `mes/bartender-cloud/printer/list/response` | `access_token`, `query` |
| `CloudGetPrinter` | GET | `/api/devices/printers/{value.json.printer_id}` | `mes/bartender-cloud/printer/get` | `mes/bartender-cloud/printer/get/response` | `access_token`, `printer_id` |

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

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 BarTenderCloud WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://am1.bartendercloud.com"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '45'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT CloudSubmitScript
        WITH SOURCE_TOPIC "mes/bartender-cloud/script/submit"
        WITH DESTINATION_TOPIC "mes/bartender-cloud/script/submit/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/api/actions?{value.json.query}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{value.json.body}"
    ADD EVENT CloudListScripts
        WITH SOURCE_TOPIC "mes/bartender-cloud/script/list"
        WITH DESTINATION_TOPIC "mes/bartender-cloud/script/list/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/actions?{value.json.query}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
    ADD EVENT CloudGetScriptStatus
        WITH SOURCE_TOPIC "mes/bartender-cloud/script/get"
        WITH DESTINATION_TOPIC "mes/bartender-cloud/script/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/actions/{value.json.script_id}?{value.json.query}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
    ADD EVENT CloudUpdateScript
        WITH SOURCE_TOPIC "mes/bartender-cloud/script/update"
        WITH DESTINATION_TOPIC "mes/bartender-cloud/script/update/response"
        WITH METHOD "PATCH"
        WITH ENDPOINT "/api/actions/{value.json.script_id}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{value.json.body}"
    ADD EVENT CloudListScriptVariables
        WITH SOURCE_TOPIC "mes/bartender-cloud/script-variable/list"
        WITH DESTINATION_TOPIC "mes/bartender-cloud/script-variable/list/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/actions/{value.json.script_id}/variables"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
    ADD EVENT CloudGetScriptVariable
        WITH SOURCE_TOPIC "mes/bartender-cloud/script-variable/get"
        WITH DESTINATION_TOPIC "mes/bartender-cloud/script-variable/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/actions/{value.json.script_id}/variables/{value.json.variable}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
    ADD EVENT CloudListPrinters
        WITH SOURCE_TOPIC "mes/bartender-cloud/printer/list"
        WITH DESTINATION_TOPIC "mes/bartender-cloud/printer/list/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/devices/printers?{value.json.query}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
    ADD EVENT CloudGetPrinter
        WITH SOURCE_TOPIC "mes/bartender-cloud/printer/get"
        WITH DESTINATION_TOPIC "mes/bartender-cloud/printer/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/devices/printers/{value.json.printer_id}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
```

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

## Usage example

Call `CloudSubmitScript` 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 'mes/bartender-cloud/script/submit/response' &
mosquitto_pub -t 'mes/bartender-cloud/script/submit' -m '{"access_token": "<access_token>", "body": {}, "query": "<query>"}'
```

## Related

* [REST API Connectors](https://docs.coreflux.org/latest/connectors/rest-api/overview)
* [REST API Apps catalog](https://docs.coreflux.org/latest/connectors/rest-api-apps)


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