API access and tokens

Everything you can do in the UI is also available through the REST API, rooted at /api. Use it to script routine work or to connect InfraBuffet to CI pipelines and other tools. Your instance serves an interactive API reference at /api/swagger/ and the machine-readable specification at /api/swagger/openapi.json. Treat them as the source of truth for routes, request fields, and response schemas.

Get a token

Scripts authenticate with an API token. To create one:

  1. Open the user menu and select API tokens.
  2. Click Create API token.
  3. Enter a Name that identifies the integration, such as ci-pipeline.
  4. Optionally set an expiration. Without one, the token never expires.
  5. Select Read only if the integration only needs to look at things.
  6. Click Create API token and copy the secret.

The secret is shown only once. If you lose it, create a new token.

A token acts as you, with your current permissions. It does not give access to any team or scope you cannot already use, and it loses access when you do. A read-only token rejects every request that changes something (POST, PATCH, PUT, and DELETE). That includes scheduling a diff, because scheduling is a POST request.

Superusers see all tokens under Admin > API Tokens and can create a token on behalf of another user.

Rotate or revoke a token

Tokens cannot be edited. To change a token’s name, expiration, or read-only setting, or to rotate a secret:

  1. Create a replacement token.
  2. Update the integration to use it.
  3. Delete the old token from the API tokens page.

Deleting a token revokes it immediately.

Make a request

Pass the token in the Authorization header and always use HTTPS:

curl -H "Authorization: Bearer $IBF_TOKEN" \
  'https://ibf.example.com/api/scopes?mine=true'

Keep the token in a secret store or environment variable rather than in scripts or version control. If a request carries an invalid token, it fails even when it also has a valid session cookie.

Lists, updates, and errors

  • Pagination: list endpoints accept pagination and the filters described in the specification. The defaults are page 1 and size 50. A list returns items, total, and last_page. Keep fetching pages until last_page is true.
  • mine=true: on infrastructures and scopes, this filter returns only those of teams you actually belong to, even if you are a superuser.
  • PATCH: only the fields you send are updated. Some nullable settings can be cleared by sending null.
  • Request fields. Use the request schema to find supported keys. POST and PATCH ignore unsupported keys.
  • Block values: they are replaced as a whole rather than merged, although secrets you omit are preserved. See working with blocks.
  • Error format: errors carry code, category, and detail, plus field information where relevant.
  • Error statuses: a 401 means authentication failed, a 403 means you lack access, and validation or conflict errors mean the request or the current state needs fixing. Do not retry errors blindly.

Run a diff and apply it

Diffs and applies run as asynchronous jobs:

POST /api/scopes/{id}/calcdiff
GET  /api/jobs/{job_id}
POST /api/scopes/{id}/applyplanned
  1. Schedule a diff with POST /api/scopes/{id}/calcdiff. Send {"block_ids": [11, 12]} to target specific blocks, or omit the body to cover the whole scope.
  2. Poll GET /api/jobs/{job_id} with the returned job ID until the job finishes, then review its result.
  3. Apply with POST /api/scopes/{id}/applyplanned and {"plan_job_id": 123}, where 123 is the ID of the successful diff job for that scope.

The worker re-verifies the plan before applying. If the scope changed in the meantime, run and review a new diff. Keep a human review step between the diff and the apply.

A read-only token can inspect jobs it has access to, but it cannot schedule or cancel them. See jobs for status meanings and recovery.