Skip to main content

Tdarr CLI

Tdarr CLI (tdarr-cli) is a command-line tool that controls Tdarr through its API. It can do almost everything the web UI can, from a terminal, a script or an AI agent. It's included from Tdarr 3.11.00.

Where to find it​

  • Windows, Linux and macOS: in the tools folder of Tdarr_Server and Tdarr_Node (tdarr-cli.exe on Windows). Run it from there, or add the folder to your PATH.
  • Docker: on the PATH, e.g. docker exec -it tdarr tdarr-cli status.

tdarr-cli is a single file, so you can also copy it to another computer with the same operating system and CPU type. Outside a Tdarr install it can't read the install's config, so set the Server with a profile.

Getting started​

tdarr-cli config init
tdarr-cli status

config init sets up a profile: a saved Server URL and API key, both checked against the Server. It also runs by itself the first time you use the CLI in a terminal, unless you give --server, --api-key, --token or their environment variables.

If authentication is enabled, create an API key for the CLI in the web UI under Tools -> API Keys. If the install's config already has a key (a Node's apiKey or the Server's seededApiKey), config init offers to reuse it, but it's safer to give the CLI its own key.

Finding commands​

Each command has its own help, with its options and examples. Start at the top and go down one level at a time:

tdarr-cli --help
tdarr-cli library --help
tdarr-cli library create --help

The help marks commands that need Tdarr Pro or an admin login. Commands marked "Rust server only" work on every 3.x Server; a 2.x Server needs TDARR_ENGINE=rust for them.

caution

tdarr-cli file delete and tdarr-cli file delete-failed delete files from disk. tdarr-cli library delete, library remove-files and file forget only remove records from the Tdarr database, and files on disk aren't touched.

caution

tdarr-cli db reads and writes documents as they're stored, without the checks other commands make. For common tasks, use library, flow, automation, variable, settings, user and api-key instead, and back up the database first with tdarr-cli backup create.

Connecting and logging in​

Server URL​

tdarr-cli uses the first of these that's set:

  1. --server or the TDARR_SERVER environment variable.
  2. The active profile's Server.
  3. The Server used by the Tdarr install the CLI runs from, read from Tdarr_Server_Config.json or Tdarr_Node_Config.json.
  4. http://localhost:8266.

API keys​

Save an API key in the active profile with:

tdarr-cli config set api-key

The key is read from a hidden prompt, or from stdin when there's no terminal, which keeps it out of your shell history. A saved key belongs to its profile's Server and is never sent to a different Server. A key the Server rejects isn't saved.

You can also give a key with the TDARR_API_KEY environment variable, or with --api-key, which leaves it in your shell history.

Admin-only commands​

API keys can't run admin-only commands, such as user and api-key. For those, log in as an admin user:

tdarr-cli config login --username admin

The password is read from a hidden prompt, or from stdin when there's no terminal. The login token is saved for the Server the CLI uses and lasts 60 days. Only admin-only commands use it; everything else keeps using the API key. To use a token for every command instead, give it with --token or the TDARR_TOKEN environment variable.

If the Server was started with seededApiKey before any user existed, its first admin user is admin, and the seeded key is its password. See Automatic Admin User Creation.

Profiles​

Each profile holds a Server URL, an API key and a login token. Use profiles to switch between Servers:

tdarr-cli config use --create remote        # create a profile and make it active
tdarr-cli config set server https://tdarr.example.com
tdarr-cli config set api-key
tdarr-cli config profiles # list profiles
tdarr-cli config use default # switch back
tdarr-cli --profile remote status # use a profile for one command

tdarr-cli config show prints the config file, Server and credentials in use, and checks them against the Server.

Config file​

Profiles are saved in Tdarr_CLI_Config.json. The CLI uses the first of these:

  1. The file given with --config-file or the TDARR_CLI_CONFIG_FILE environment variable.
  2. Tdarr_CLI_Config.json in the configs folder of the Tdarr Server or Node install the CLI runs from, if it exists. In Docker, this is your mapped /app/configs folder, so profiles survive recreating the container.
  3. tdarr/Tdarr_CLI_Config.json in your user config folder, if it exists:
    • Windows: %APPDATA%\tdarr\
    • macOS: ~/Library/Application Support/tdarr/
    • Linux: $XDG_CONFIG_HOME/tdarr/, or ~/.config/tdarr/

If neither file exists yet, a new one goes in the install's configs folder when the CLI runs from an install, and in your user config folder otherwise.

caution

The config file holds API keys and login tokens. Keep it private.

Global options​

These options work with every command, before or after the command name:

OptionEnvironment variableDescription
-s, --server <URL>TDARR_SERVERTdarr Server URL, e.g. http://192.168.1.10:8266
-k, --api-key <KEY>TDARR_API_KEYAPI key
--token <TOKEN>TDARR_TOKENLogin token, sent instead of the API key
--profile <NAME>TDARR_PROFILEProfile to use instead of the active one
--config-file <PATH>TDARR_CLI_CONFIG_FILEConfig file to use
-o, --output <FORMAT>human, json or raw. Default: human in a terminal, json when piped
--timeout <SECONDS>Seconds to wait for the Server, or 0 to wait as long as it takes. Default: 60
-y, --yesAnswer yes to confirmation questions
-v, --verbosePrint the config file, Server and credentials in use, and each request and its response status, to stderr
--no-inputTDARR_NO_INPUTNever prompt or ask questions. This is automatic when stdin or stderr isn't a terminal

Output​

Commands print a short summary by default:

  • --full prints every field, as JSON.
  • get commands take a key to print one field. a.b is field b inside a.
  • Long lists stop at --limit. Use --limit 0 for everything.

In a terminal, output is readable text and tables. When piped, or with -o json, it's pretty-printed JSON. -o raw prints JSON on one line, and tdarr-cli api call -o raw prints the response exactly as the Server sent it.

Scripting​

Exit codes​

CodeMeaning
0Done
1Failed
2Bad input, such as a name that matches nothing, or a request the Server refused
3Not allowed: login, API key, admin role or Tdarr Pro
4Can't reach the Server

Confirmations​

Commands that make big changes, such as deleting, restarting or requeuing a whole library, ask to confirm first. When there's no terminal to ask in, such as in a script or a scheduled task, add --yes.

Waiting for something​

tdarr-cli has no wait flags. Loop on a command instead:

until tdarr-cli server ready; do sleep 5; done

tdarr-cli server ready exits with 1 while the Server isn't ready to hand out work, and 4 while it can't be reached.

Names, quotes and JSON​

  • Libraries, Nodes, flows and automations can be given by name or ID. A restarted Node may come back with a new ID, so use its name in scripts.

  • Put values with spaces in double quotes, which work in every shell:

    tdarr-cli library scan "Kids Movies"
    tdarr-cli library set Movies "name=Kids Movies"
  • Each shell quotes inline JSON differently, so give JSON as @file.json, or - to read stdin:

    tdarr-cli api call cruddb --data @body.json
    cat body.json | tdarr-cli api call cruddb --data -
  • Git Bash on Windows turns Server paths such as /media/movies into C:/Program Files/Git/media/movies, even in quotes. Start the command with MSYS_NO_PATHCONV=1 to stop it.

Secrets​

Commands that take a secret read it from a hidden prompt, or from stdin when there's no terminal. In scripts, pipe the secret in so it stays out of your shell history:

printf '%s\n' "$KEY" | tdarr-cli config set api-key
printf '%s\n' "$PASSWORD" | tdarr-cli config login --username admin
printf '%s\n' "$PRO_KEY" | tdarr-cli settings set tdarrKey

Shell completion​

tdarr-cli completions prints a completion script for bash, zsh, fish, PowerShell or elvish:

tdarr-cli completions bash > ~/.local/share/bash-completion/completions/tdarr-cli
tdarr-cli completions zsh > "${fpath[1]}/_tdarr-cli"
tdarr-cli completions fish > ~/.config/fish/completions/tdarr-cli.fish
tdarr-cli completions powershell >> $PROFILE

Calling the API directly​

tdarr-cli api calls API endpoints directly and is stable like the API: its commands, output and exit codes don't break between versions. The other commands, such as tdarr-cli library scan, are built for tasks and may change between versions, so use tdarr-cli api in scripts that must keep working after you update Tdarr.

tdarr-cli api list                      # endpoints, and the CLI command for each
tdarr-cli api list --all # also Node-internal, outdated and browser-only endpoints
tdarr-cli api describe scan-files # an endpoint's description and request fields
tdarr-cli api call status
tdarr-cli api call cruddb --data @body.json

Most POST endpoints expect their fields inside a data object. For example, body.json for cruddb:

{"data": {"collection": "FlowsJSONDB", "mode": "getAll"}}

The response is printed even when the Server answers with an error. The error and its HTTP status then go to stderr.