---
title: "Scripting recipes | Hostemi"
description: "A nightly price check, bookings to CSV, a cron job and a CI step, written against the JSON output. From the Hostemi docs for vacation rental hosts."
canonical: https://hostemi.com/docs/cli/scripting
source: https://hostemi.com/docs/cli/scripting.md
---

# Scripting recipes

A nightly price check, bookings to CSV, a cron job and a CI step, written against the JSON output.

#### On this page

1. [Rules for scripts](#rules-for-scripts)
2. [Bookings to CSV](#bookings-to-csv)
3. [A nightly price check](#a-nightly-price-check)
4. [A cron job](#a-cron-job)
5. [Close nights from a script](#close-nights-from-a-script)
6. [Any API route](#any-api-route)

## Rules for scripts

- Sign in with `HOSTEMI_TOKEN`, not `login`.
- Use `--json` and read the exit code; never parse the tables.
- Reads never ask. A change needs `--yes`, and exit 4 means it waits for the host: send the `approvalUrl` to a person.
- On exit 1 read `error.code`; a rate limit says when to try again in `error.message`.

## Bookings to CSV

The report commands print CSV on stdout:

```bash
hostemi reports bookings --from 2026-01-01 --to 2026-12-31 > bookings-2026.csv
hostemi reports export --from 2026-01-01 --to 2026-12-31 > revenue-2026.csv
```

Or shape your own from the JSON (the answer of `GET /public/v1/reservations`):

```bash
hostemi bookings list --from 2026-12-01 --to 2026-12-31 --json \
  | jq -r '.reservations[] | [.arrivalDate, .departureDate, .guest.firstName, .guest.lastName, .status, .totalAmountMinor, .currency] | @csv'
```

## A nightly price check

Pace per listing for the next weeks (nights for sale, sold, free, sold in the last 7 days), saved once a night for comparison:

price-check.sh

```bash
#!/bin/sh
set -eu
day=$(date +%F)
hostemi pricing pace --json > "$HOME/hostemi-pace/$day.json"
# one listing in detail: weeks, last year at the same point, booking curve, the lowest price
hostemi pricing signals <listing id> --json > "$HOME/hostemi-pace/$day-lake-house.json"
```

The signals are numbers only; deciding a price stays with you (or your AI, through a preview).

## A cron job

crontab -e

```text
# every night at 05:10, with the key from a file only you can read
10 5 * * * HOSTEMI_TOKEN=$(cat $HOME/.hostemi-key) /usr/local/bin/hostemi pricing pace --json > $HOME/hostemi-pace/latest.json 2>> $HOME/hostemi-pace/errors.log
```

Use the full path of `hostemi` (`which hostemi`): cron has a short `PATH`.

## Close nights from a script

```bash
if hostemi block <listing id> 2026-12-24:2026-12-26 --reason "family" --yes --json > out.json; then
  echo "blocked"
else
  code=$?
  if [ "$code" -eq 4 ]; then
    echo "waits for the host: $(jq -r .approvalUrl out.json)"
  else
    echo "failed ($code): $(jq -r .error.message out.json)"
  fi
fi
```

In the default setting ("Ask before changes") every change from a key waits for the host, so exit 4 is the normal outcome there.

## Any API route

```bash
hostemi api GET units --json
hostemi api GET reservations --query from=2026-12-01,to=2026-12-31 --json
hostemi api POST /public/v1/blocks --data '{"unitId":"…","firstNight":"2026-12-24","lastNight":"2026-12-26"}' --dry-run
```

`hostemi api` uses the same sign-in and the same approval rules: GET reads, anything else asks first (or `--yes`).

Documentation pages

Something missing from this page? Write to [hello@hostemi.com](mailto:hello@hostemi.com), or use the form on the [Help](https://hostemi.com/help) page.
