Docs
Live demo

API quick start

Create a token and grant access with curl.

On this page

1. Create a token#

  1. Open profile → API tokens → New token.
  2. Set Name, Role (Viewer or Admin) and Expires in, click Create token.
  3. Copy the token (shown once) and export:
    bash
    export PRINCIPAL_URL=https://principal.example.com
    export AUTH="Authorization: Bearer prn_pat_..."

Use an organization token for shared scripts (Authentication).

2. List targets#

bash
curl -sH "$AUTH" "$PRINCIPAL_URL/api/v2/targets?limit=5"

Returns items, has_more, next_cursor (Lists). Copy warehouse-staging’s id.

3. Find group and template#

  1. Look up both:
    bash
    curl -sH "$AUTH" "$PRINCIPAL_URL/api/v2/identities?kind=group&search=analytics"
    curl -sH "$AUTH" "$PRINCIPAL_URL/api/v2/access-templates/warehouse-read-only"
  2. On 404, create the template (Rules and templates):
    bash
    curl -sX POST "$PRINCIPAL_URL/api/v2/access-templates" \
      -H "$AUTH" -H "Content-Type: application/json" \
      -d '{"name":"warehouse-read-only","engine":"postgres",
        "body":{"targeting":{"discovery":{"database":"app"}},
        "grants":[{"target":"public.*","privileges":["SELECT"]}]}}'

4. Create, preview and apply#

  1. Create the rule:
    bash
    curl -sX POST "$PRINCIPAL_URL/api/v2/policies" \
      -H "$AUTH" -H "Content-Type: application/json" \
      -H "Idempotency-Key: $(uuidgen)" \
      -d '{"subject_id":"<group id>","target_id":"<target id>",
        "template_name":"warehouse-read-only"}'
  2. Preview, then apply:
    bash
    curl -sX POST -H "$AUTH" "$PRINCIPAL_URL/api/v2/policies/<rule id>/plan/diff"
    curl -sX POST -H "$AUTH" "$PRINCIPAL_URL/api/v2/policies/<rule id>/apply"

Returns 202 with job_id. Track via GET /apply-runs or GET /admin/jobs/{id} (Async).

5. Handle errors#

json
{"status":409,"code":"policy.access_held_by_group_rule","detail":"..."}

Branch on code, not text (Errors).

↑ ↓ to moveEnter to openEsc to close