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

# Scripting with the CLI

Practical notes for using [`hostinger`](/api-reference/cli.md) 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:

```bash
hostinger hosting websites list --format json | jq
```

Diagnostics — 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:

```bash
if ! out=$(hostinger hosting websites list --format json 2>/dev/null); then
  echo "request failed: $out" >&2
  exit 1
fi
```

> **Note:** 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:

```bash
hostinger dns records update example.com --zone '[
  {
    "name": "@",
    "type": "A",
    "ttl": 3600,
    "records": [{ "content": "192.0.2.1" }]
  }
]'
```

There is no `@file.json` or standard-input form. To keep a payload in a file, expand it yourself with command substitution:

```bash
hostinger dns records update example.com --zone "$(cat zone.json)"
```

> **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:

```bash
hostinger dns records update example.com --overwrite=false --zone '...'
```

Take a snapshot first, so you have a rollback:

```bash
hostinger dns snapshots list example.com
```

**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:

```bash
export HOSTINGER_API_TOKEN=<your API token>
```

A configured token takes precedence over browser sign-in, and no browser will be opened. Generate tokens in [hPanel → API](https://hpanel.hostinger.com/api) and treat them like passwords — see [Security & Access](/account/security.md).

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 `logout` command. 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*
