Scripting with the CLI
Use the hostinger CLI in scripts and CI — exit codes, JSON output and piping, passing JSON to flags, destructive defaults, and credentials for unattended runs.
Practical notes for using hostinger in shell scripts, CI pipelines, and bulk operations. These are the behaviors that aren't obvious from --help.
Machine-readable output
--format json prints the API response unchanged, which makes it safe to pipe:
hostinger hosting websites list --format json | jqDiagnostics — the "Using config file" notice and any deprecation warnings — go to standard error, not standard output. Piping standard output never picks up that noise, so you don't need to filter it.
Exit codes
The CLI exits 0 on success and 1 on failure. When the API returns an error, the raw response body is printed so you can read the message or parse it:
if ! out=$(hostinger hosting websites list --format json 2>/dev/null); then
echo "request failed: $out" >&2
exit 1
fiNote: Every failure uses exit code
1— an API error, an invalid flag value, and malformed JSON are indistinguishable by code alone. Check the output when you need to tell them apart.
Passing JSON to flags
Some flags take a JSON value rather than a scalar. They're marked (JSON) in the help output, and there are 16 of them across the CLI — including --zone on dns records update, --items and --coupons on billing orders create-purchase, and the body flags on wordpress installations install and reach segments create.
The value is parsed as JSON before any request is sent, so a quoting mistake fails immediately and costs nothing. Wrap the whole value in single quotes so the shell leaves the double quotes alone:
There is no @file.json or standard-input form. To keep a payload in a file, expand it yourself with command substitution:
Note: In PowerShell, single quotes don't behave the same way. Read the file into a variable and pass that instead, or escape the inner double quotes.
Commands worth being careful with
About 60% of the available operations change state, so a loop over a list of sites or machines deserves a dry run first. Two things in particular:
dns records update overwrites by default. --overwrite defaults to true, which deletes records matching a name and type and recreates them. To append and update instead of replacing, set it explicitly:
Take a snapshot first, so you have a rollback:
Deletes are immediate. There are 42 delete operations, plus verbs like recreate, reset-hostname, and purge-lite-speed that discard state without a separate confirmation step. Nothing prompts you.
Read-only verbs — list, get, info, and the various show-* commands — are safe to explore freely, and make up the other 40%.
Credentials for unattended runs
Browser sign-in is convenient on a workstation but useless in CI, because nothing can complete the flow. For automation, set a token instead:
A configured token takes precedence over browser sign-in, and no browser will be opened. Generate tokens in hPanel → API and treat them like passwords — see Security & Access.
Interactive sign-in caches its tokens outside the config file, at ~/.config/hostinger/api-cli/credentials.json (%APPDATA%\hostinger\api-cli\credentials.json on Windows), with owner-only permissions.
Note: There is currently no
logoutcommand. To sign out, or to switch to a different Hostinger account, delete that credentials file — the next command will start a fresh sign-in.
Last updated: August 5, 2026
Last updated
Was this helpful?