Automating / API
API
The app itself, answered as JSON to a token that acts as you, with your role, and asks before anything costly.
The API is the app itself: the same addresses the browser uses, answered as JSON. There is no
/api prefix and no second set of controllers to fall behind the first. The CLI and
the MCP server are built on it.
GET /openapi describes every action that answers JSON, generated from the routes and the
controllers themselves rather than written by hand.
Tokens
A token belongs to a person and acts as that person, with their role on that team. Make one at
Settings → Connected apps, or let hoster login make one through the browser. Tokens are made
and revoked in the browser only: a token cannot mint another.
A token can be read-only. It may only read, anything else answers 403, and it is never
handed a secret.
The token is shown once. Only its digest is stored, so a stolen database yields nothing.
Tokens start with hst_, so one found in a log or a repository is recognisable for what it is.
There is no install-wide token: a script signs in as a person.
Authenticating
Send the token, and ask for JSON:
curl -H "Authorization: Bearer $HOSTER_TOKEN" -H "Accept: application/json" \
https://app.kamalcloud.com/123456789/apps
Addresses start with your team’s id, as in the browser.
Changing things
Writes take the same parameters as the browser’s forms, as JSON:
curl -X POST -H "Authorization: Bearer $HOSTER_TOKEN" \
-H "Content-Type: application/json" -H "Accept: application/json" \
-d '{"app": {"name": "docs", "repository": "git@github.com:acme/docs.git"}}' \
https://app.kamalcloud.com/123456789/apps
Anything that costs money, cannot be undone or takes something offline answers 428 with a
sentence saying what it would do. Show that to the person, and send the same request again with
confirm: true once they agree.
Deleting an environment, or an app that has environments, wants an authenticator code, so it is browser-only and answers 406 here.
Responses
| Status | When |
|---|---|
200 |
A read, or a change answered with the record as it now is |
201 |
A record was made; Location is its address |
202 |
Work started that settles on its own, such as a deploy or a backup; read it until it does |
204 |
A change or removal with nothing more to say |
401 |
No token, or one that is revoked or expired |
402 |
A write while the team’s subscription has lapsed |
403 |
Your role may not do that, or the token is read-only |
404 |
No such record on this team |
406 |
The action is browser-only |
409 |
Something already running stands in the way, such as another deploy |
422 |
The change was refused: { "errors": [...] } |
428 |
It needs confirm: true first |
Every record carries type, id, name and url, and every list starts with a one-line
summary. Lists come 20 to a page, with ?page=.
Giving a token to an agent
Give it the role you would give a person doing the same job, and a read-only sign-in unless it has to change something. Anything costly still comes back for a yes before it happens.