> For the complete documentation index, see [llms.txt](https://developers.newbluefx.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.newbluefx.com/captivate-api/advanced-api-reference/api-communication.md).

# API Communication

> **Note:** Every request on this page needs Full API Access, except the notification commands (`subscribe`, `unSubscribe` and `getSubscriptions`). See [API Access Levels](https://developers.newbluefx.com/getting-started/api-access-levels.md).

### Equivalent to `ServiceHandler.scheduler.scheduleCommand` <a href="#equivalent-to-servicehandlerschedulerschedulecommand" id="equivalent-to-servicehandlerschedulerschedulecommand"></a>

To call `scheduleCommand`, send a JSON-encoded string that will decode to an object with the following fields:

* `command`: *string*. The name of the command to run.
* `parameters`: *object*. The parameters as an object.
* `variables`: *object*. The variables as an object.

**Netcat Example:**

```sh
MSG=$'{"command": "readTitle", "parameters":{"title":"Test"}}\r\n'
( echo $MSG; sleep 1; ) | nc localhost 9025
```

**Curl Example:**

```sh
curl --data '{"command": "readTitle", "parameters":{"title":"Test"}}' \
     -H 'Content-Type: application/json' \
     http://localhost:9022/api/
```

### Equivalent to `ServiceHandler.scheduler.scheduleAction` <a href="#equivalent-to-servicehandlerschedulerscheduleaction" id="equivalent-to-servicehandlerschedulerscheduleaction"></a>

To call `scheduleAction`, send a JSON-encoded string that will decode to an object with the following fields:

* `action`: *string*. The name of the action to schedule.
* `input`: *string*. The name of the input/data controller to target, leave blank to target all.
* `title`: *string*. The id or name of the title/graphic layer to target, leave blank to target all.
* `variables`: *object*. The variables as an object.

```sh
curl --data '{"action": "update", "title": "My Title", "variables": {"Time": "00:00", "Message": "Go!"}}' \
     -H 'Content-Type: application/json' \
     http://localhost:9022/api/
```

### Equivalent to `ServiceHandler.scheduler.updateInputDefinition` <a href="#equivalent-to-servicehandlerschedulerupdateinputdefinition" id="equivalent-to-servicehandlerschedulerupdateinputdefinition"></a>

To call `updateInputDefinition`, send a JSON-encoded string that will decode to an object with the following fields:

* `redefine`: *string*. The name of the input/data controller to target.
* `definition`: *object*. The variables “definition” object (see `updateInputDefinition` on the JavaScript API documentation).

```sh
curl --data '{"redefine": "My Input", {"method": "merge", "variables": {"Clock":{"pattern":"[0-9][0-9]:[0-9][0-9]"}}}}' \
     -H 'Content-Type: application/json' \
     http://localhost:9022/api/
```

### Equivalent to `ServiceHandler.scheduler.saveSettings/loadSettings` <a href="#equivalent-to-servicehandlerschedulersavesettingsloadsettings" id="equivalent-to-servicehandlerschedulersavesettingsloadsettings"></a>

To call `saveSettings` or `loadSettings`, send a JSON-encoded string that will decode to an object with the following fields:

* `settings`: *object*|*string*. For loading, use the word `load`. For saving, use an object or any string other than `load`.
* `input`: *string*. The name of the input / data controller for which to load or save settings.

```sh
# save {"name": "value"} to the settings
curl --data '{"input":"API Tour: JSON Command Tester", "settings": {"name":"value"}}' \
     -H 'Content-Type: application/json' \
     http://localhost:9022/api/
# {"result":null}

# load from the settings
curl --data '{"input":"API Tour: JSON Command Tester", "settings": "load"}' \
     -H 'Content-Type: application/json' \
     http://localhost:9022/api/
# {"result":{"name":"value"}}
```

### Handling Results <a href="#handling-results" id="handling-results"></a>

The results of an advanced API call will be exactly the same as the main JavaScript API with the following modifications:

* Successful responses will be wrapped in an object where `result` is the key to the actual Captivate response.

  ```json
  {
    "result": {
      "command": "schedule",
      "reply": "schedule",
      "success": true
    }
  }
  ```
* If the call failed, the response will be an object where `error` is the key to the error message.
* If the edition does not have the API access level the call needs, the response will be `{"result": {"error": "automation_entitlement_required"}}`, and the call does nothing. See [API Access Levels](https://developers.newbluefx.com/getting-started/api-access-levels.md).
* If the call is one of the asynchronous commands that passes information back through the notification system, you will need to be subscribed to notifications to receive it. See below.

### Handling Notifications <a href="#handling-notifications" id="handling-notifications"></a>

When a client connects to the TCP socket or issues an HTTP GET to `/api/subscribe`, it will immediately be subscribed to all `play` and `data` events sent from Captivate. Whenever a notification message is received from Captivate, it is passed to the client as a JSON-encoded string terminated with CRLF (`\r`).

Notification messages will be wrapped in an object where `notification` is the key to the actual notification content (or `error` as above if there was an error subscribing to the notification stream):

```json
{
  "notification": {
    "channel": -1,
    "command": "notify",
    "event": "play",
    "id": "{cd654eba-4afe-4838-ad75-65ff823ac0dd}",
    "input": "",
    "play": "Running",
    "sender": "", // `sender` as given in the parameters of the "subscribe" command
    "title": "Acrylic Baseball Scoreboard",
    "to": ""
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.newbluefx.com/captivate-api/advanced-api-reference/api-communication.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
