Scripting with the CLI

Three output formats, and why JSON plus jq is where the CLI earns its place.

Updated

Choose an output format

-o or --output takes table, json, or csv. Table is the default and is for reading; the other two are for feeding something else.

screenly screen list                 # table, for a human
screenly screen list -o json         # for jq
screenly screen list -o csv          # for a spreadsheet

CSV is the one to remember when somebody asks for a fleet inventory. It goes straight into a spreadsheet without anyone writing a script.

JSON and jq

screenly screen list -o json | jq -r '.[] | select(.status.is_online == false) | .name'

That is the shape of most useful one-liners: list something, filter it, print the field you care about.

Piping in and out

Fetching, transforming, and piping back is the intended style:

screenly playlist get $PLAYLIST_ID -o json \
  | jq '...' \
  | screenly playlist update

Things worth scripting

Bulk provisioning is a loop over pairing codes and names, from an inventory file.

Content rollouts add an asset, then append it to a playlist with a duration.

screenly asset add throughput.html "Throughput Board"
screenly playlist append $PLAYLIST_ID $ASSET_ID 20

Fleet reports are a scheduled screen list -o csv into whatever your organization already reads.

Authenticated pages are basic-auth, bearer-auth and inject-js applied consistently across many assets, rather than clicked one at a time.

Permissions

The CLI carries the permissions of the token, which carries the permissions of the account that made it. A script that only uploads content is safer with a token from an account that can only upload content. See API tokens.

Was this page helpful?

Thanks. Glad it helped.

Thanks. That tells us where to look next.

Type to search the documentation