# scheduleCommand Method

This is the single most powerful API call, and it exposes a rich suite of functions for extensive control.

```javascript
// callback version (first three arguments are required)
ServiceHandler.scheduler.scheduleCommand(command, parameters, variables, (res) => {
  let data;
  try {
    data = JSON.parse(res);
  } catch (e) {
    data = { result: res };
  }
  console.log(data);
});

// promise version (results will be parsed for you)
const data = await ServiceHandler.scheduler.scheduleCommand(command, parameters, variables);
console.log(data);
```

* `command`: String containing the command; see below for options.
* `parameters`: JavaScript object of keys and values determined by the command.
* `variables`: JavaScript object of variable names and values.
* `callback`: Function to be called with a **JSON-formatted string** of the command results.

Available commands include but are not limited to these:

| command                | what it does                                                                                        |
| ---------------------- | --------------------------------------------------------------------------------------------------- |
| `schedule`             | Internal version of the `scheduleAction` command.                                                   |
| `macro`                | High level title playback control.                                                                  |
| `setTitleInput`        | Assign an input to the title.                                                                       |
| `removeTitleInput`     | Remove an input from a title.                                                                       |
| `setTitlePosition`     | Reposition a title in the list.                                                                     |
| `loadTitle`            | Load a title from file, and optionally give it a new name, position, and id.                        |
| `saveTitle`            | Save the selected title to file.                                                                    |
| `newTitle`             | Create a new title.                                                                                 |
| `readTitle`            | Get detailed information on a title graphic and its variables.                                      |
| `setDynamic`           | Specify whether a variable is allowed to change in a title by setting dynamic to 1 or 0             |
| `downloadImage`        | Download image from a url or parse from a `data:` string, save it to temp file, and return the path |
| `getPlayStatus`        | Get the playback status of the specific title and variables.                                        |
| `getRenderStatus`      | Get the render status of a title.                                                                   |
| `getTitlesPlayStatus`  | Returns a list of all titles and their input and play status.                                       |
| `getInputsPlayStatus`  | Returns a list of all inputs and play status on the requested channel.                              |
| `getAllVideoIns`       | Returns a list of all video devices available for input                                             |
| `getAllAudioIns`       | Returns a list of all audio devices available for input                                             |
| `isTitleConnected`     | Returns true if at least one title in the provided channel is connected to one of a list of inputs. |
| `getTitlesConnected`   | Returns a list of all titles that are connected to the specified input (or all if input is empty).  |
| `getTitleControlInfo`  | Get extensive information for all titles, just one title, or titles connected to the input.         |
| `getTitleConnnectInfo` | Get all information pertaining to the connection between inputs and titles.                         |
| `getCachePath`         | Gets the current location for the specified title’s cache                                           |
| `setCachePath`         | Sets a unique location to build the cache for the requested title                                   |
| `subscribe`            | Subscribe for notifications when titles change play state or their data is updated.                 |
| `unSubscribe`          | Unsubscribe for notifications when titles change play state or their data is updated.               |
| `getSnapShot`          | Request a rendering of a title with specific variable settings - can be used to preview.            |
| `getTitleIcon`         | Request a rendering of a title, but only if it has changed since last time.                         |
| `openFileDialog`       | Open a file browser to select a file and return its full path.                                      |
| `getFileContent`       | Read a file (or url) and return its data - useful for files that need to be polled for changes.     |
| `fetchUrl`             | Perform an arbitrary web request similar to JavaScript's `fetch` command                            |
| `encodeImage`          | Encodes an image from a file to a dataUrl for easy display in a web UI.                             |
| `assignVariable`       | Assign an input variable to a graphic variable.                                                     |
| `popupAssignVariable`  | Open a popup menu to connect the variable to a field in the title.                                  |
| `openDesigner`         | Open the title designer with the requested title.                                                   |
| `closeDesigner`        | Close the title designer.                                                                           |
| `openUrl`              | Open URL in the default system browser.                                                             |
| `... custom message`   | When using the `to` field, your message will be passed to passed to other controllers               |

> Note: Most commands can be targeted to a specific channel, and the channel should be specified as a number starting at `0`. This is different from the way channels are displayed in the project panel. The tab labeled “Channel 1” is accessed as channel `0`.

**Example:**

```javascript
// remember, when using the promises version, the response data will be parsed for you
const res = await ServiceHandler.scheduler.scheduleCommand(
  'downloadImage',
  { url: 'http://my-images.com/image.jpg' },
  {}
);
if (res.success) {
  console.log(`Image downloaded to local cache: ${res.path}`);
  ServiceHandler.scheduler.scheduleAction(action, inputName, titleId, { 'My Image': res.path });
}
```

There are many more commands than these, including commands to start and join Zoom meetings, commands to retrieve chat messages from a video conference. For a full description of these and all currently available commands, view the [All Commands Reference](https://developers.newbluefx.com/captivate-api/all-commands-reference).

Additionally, we provide a [JSON Command Tester](https://developers.newbluefx.com/api-examples/json-command-tester) included in the `API Tour` data controller. You can use that controller to easily test each command and copy/paste code directly from it.

<figure><img src="https://2284285836-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXkMvk0MrY3BcyplZ0pf7%2Fuploads%2FKnwilqGuXzWOMRGpa24M%2Fjsoncommandtester.png?alt=media&#x26;token=4c7d6e34-edc7-4b7e-a9d3-bf4f0cfa3389" alt=""><figcaption></figcaption></figure>
