Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Getting started

Everything in the Terrakube UI is available through the API, so you can automate it from scripts, pipelines and your own tools. The API has two forms:

Endpoint
Use it for

/api/v1

REST, in JSON:API format. Create, read, update and delete everything.

/graphql/api/v1

GraphQL over the same data. Good for reading nested data in one request.

Both are generated from the same model and enforce the same permissions as the UI. In the examples, $API is your API URL, for example https://terrakube-api.example.com, and $TOKEN is a token.

Authenticate

Send a bearer token on every request:

export API=https://terrakube-api.example.com
export TOKEN=<token>

curl -H "Authorization: Bearer $TOKEN" "$API/api/v1/organization?fields[organization]=name"

Pick the token that fits:

Token
Use it for

Your own scripts. Acts as you.

Shared automation. Has the team's permissions.

CI systems such as GitHub Actions, with no stored secret.

terraform login token

The Terraform CLI. See CLI-driven Workflow.

A request without a valid token returns 401. A token without permission returns 403.

Read data

List and find things with filters, sorting, paging and relationships:

Parameter
Meaning

filter[type]=expression

RSQL filter such as name==prod*, status=in=(failed,cancelled) or a==1;b==2 (and). A comma between expressions means OR.

sort=name, sort=-name

Ascending or descending.

page[size], page[number], page[totals]

Paging, and a meta block with the total.

include=step

Return related records in the same response.

fields[type]=a,b

Return only some attributes.

Add -g to curl so it does not treat square brackets as ranges.

The same read as GraphQL:

Write data

Writes use Content-Type: application/vnd.api+json and a JSON:API body with type, attributes and relationships. For example, start a run:

Use PATCH to update, with the record id in the body, and DELETE to remove it. A DELETE must not carry a body or a content type.

See API-driven Workflow for the full run lifecycle from the API: start, wait, approve, and pass run-specific variables.

Reference

Last updated

Was this helpful?