# Raw API commands

Call any path of the Svanja API with your key.

Web version: https://www.svanja.com/docs/cli/api/

`svanja api get`, `svanja api post`, `svanja api patch`, and `svanja api delete` send requests to any path in the [REST API](https://www.svanja.com/docs/api/). Use them for endpoints that don't have their own command, or to test a call before you write code for it. They authenticate with your profile's key, or `SVANJA_API_KEY` when that's set, so they have the same permissions as that key. Paths are relative to the API address, like `/whoami` or `spaces`. There's no `put` command; to save a note or file, use `svanja files save`.

By default, these commands return the `data` part of the response. Pass `--raw --json` to see the full response, including `meta`. Pass `--all` to fetch and merge every page of a list. Because it merges pages, `--all` can't be combined with `--raw`.

Write requests include an idempotency key automatically, except for calls that return a one-time secret, such as creating or rotating an API key. Those run once without retries. `svanja api delete` runs without asking for confirmation. To inspect a request before it goes out, add `--dry-run` to print it without sending it.

## Commands

### svanja api delete

Send a DELETE request to an API path using the active profile and credential.

<path> is API-relative and is joined below the resolved API base. Give a path like /projects/<id> or projects/<id>. A bare first segment containing a colon is rejected as ambiguous URI syntax; a colon after an explicit leading slash or in a later segment remains opaque path data. Absolute and scheme-relative URLs, query or fragment markers, trailing slashes, and empty segments fail locally. Put query parameters in --query key=value (repeatable); values may be empty or contain commas and equals signs, and repeated values retain their order.

DELETE is an unsafe raw action and does not ask for confirmation. Choosing this leaf is the explicit decision to send it; --force is not required.

Build an optional JSON body with --field key=value (repeatable), pass any valid JSON value with --body '<json>', or read one with --body-file <path>. Use --body-file - to read from stdin. These body modes are mutually exclusive, and duplicate --field keys fail locally. A DELETE with no body sends no Content-Type and no JSON null body.

Every real DELETE sends an idempotency key so a retried request is not applied twice. A key is generated automatically; pass --idempotency-key <key> to supply your own (1-255 visible ASCII bytes). Key values are sensitive: output reports only whether a key is generated or explicit and never prints the value. Use --dry-run to preview the method, path, query, body, and idempotency behavior without resolving credentials or contacting the API.

By default the decoded "data" value of the API success envelope is printed. Use --raw to print the full success envelope, including data, meta, request_id, and unknown envelope keys. --raw and --dry-run cannot be combined.

Mark a request value as sensitive with --secret-field <name> (repeatable). Named query values, field values, and matching JSON body keys are shown as [REDACTED] in dry-run previews, --debug output, and rendered errors; the flag does not add a request value.

JSON output is the selected machine value as stable JSON. Default human and --plain output print scalar values without JSON quotes; objects, arrays, and null print as JSON because the raw shape is not known ahead of time.

--include-meta adds safe transport context under meta when --json, --jq, or --template is selected. The ordinary value moves under data; output without --include-meta remains unchanged. It cannot be combined with --dry-run.

Output modes: default human, --plain, --json stable JSON, and --jq/--template transforms over the selected JSON value.

```text
svanja api delete <path> [flags]
```

Needs a stored key (svanja login) or SVANJA_API_KEY.

| Flag | What it does |
| --- | --- |
| `--body` | JSON request body (mutually exclusive with --field and --body-file) |
| `--body-file` | read the JSON request body from a file, or - for stdin |
| `--dry-run` | preview the request without resolving credentials or contacting the API |
| `--field` | body field as key=value (repeatable; mutually exclusive with --body and --body-file) |
| `--idempotency-key` | explicit idempotency key (1-255 visible ASCII bytes); generated when omitted on replayable unsafe routes |
| `--query` | query parameter as key=value (repeatable) |
| `--raw` | print the full API success envelope instead of only data |
| `--secret-field` | request field name whose value must be redacted in debug output and errors (repeatable) |

```bash
svanja api delete /projects/<id>
svanja api delete /projects/<id> --json
svanja api delete /projects/<id> --json --include-meta
svanja api delete /projects/<id> --idempotency-key <key>
svanja api delete /projects/<id> --dry-run
svanja api delete /projects/<id> --query force=true --raw --json
svanja api delete /projects/<id> --jq .deleted
svanja api delete /projects/<id> --template '{{.deleted}}'
```

### svanja api get

Send a GET request to an API path using the active profile and credential.

<path> is API-relative and is joined below the resolved API base. Give a path like /projects or projects. A bare first segment containing a colon is rejected as ambiguous URI syntax; a colon after an explicit leading slash or in a later segment remains opaque path data. Absolute and scheme-relative URLs, query or fragment markers, trailing slashes, and empty segments fail locally. Put query parameters in --query key=value (repeatable); values may be empty or contain commas and equals signs, and repeated values retain their order.

By default the decoded "data" value of the API success envelope is printed. Use --raw to print the full success envelope, including data, meta, request_id, and unknown envelope keys.

Without pagination flags, GET performs exactly one request and does not inject page or per_page query parameters. Use --all to fetch every page, --limit to cap merged rows across pages, or --page/--per-page to fetch one exact API page. Pagination flags cannot be combined with --query page=... or --query per_page=.... --raw is allowed with --page/--per-page, but --raw cannot be used with --all or --limit because those modes merge data rows. --all=false leaves pagination inactive. When the first --all or --limit response is not a paginated array, its single data value is rendered as-is. Later response-shape or pagination drift is a protocol error and produces no partial output.

Mark a request value as sensitive with --secret-field <name> (repeatable). The named query value is shown as [REDACTED] in --debug output and rendered errors; the flag does not add a request value.

JSON output is the selected machine value as stable JSON. Default human and --plain output print scalar values without JSON quotes; objects, arrays, and null print as JSON because the raw shape is not known ahead of time.

--include-meta adds safe transport context under meta when --json, --jq, or --template is selected. The ordinary value moves under data. Decoded GET also places safe non-pagination envelope context under meta.api_meta; --raw keeps the selected full envelope under data without duplicating that context. Output without --include-meta remains unchanged.

Output modes: default human, --plain, --json stable JSON, and --jq/--template transforms over the selected JSON value.

```text
svanja api get <path> [flags]
```

Needs a stored key (svanja login) or SVANJA_API_KEY.

| Flag | What it does |
| --- | --- |
| `--all` | fetch every page |
| `--limit` | maximum total number of items to fetch across pages |
| `--page` | fetch one exact page number |
| `--per-page` | items per page (1-100) for exact page mode |
| `--query` | query parameter as key=value (repeatable) |
| `--raw` | print the full API success envelope instead of only data |
| `--secret-field` | request field name whose value must be redacted in debug output and errors (repeatable) |

```bash
svanja api get /whoami
svanja api get /whoami --json
svanja api get projects --query status=active
svanja api get projects --query status=active --raw --json
svanja api get /projects --all --json
svanja api get /projects --all --json --include-meta
svanja api get /credits/balance --jq .balance
svanja api get /projects --template '{{range .}}{{.id}}{{end}}'
svanja api get /whoami --secret-field token --query token=<token> --debug
```

### svanja api patch

Send a PATCH request to an API path using the active profile and credential.

<path> is API-relative and is joined below the resolved API base. Give a path like /projects/<id> or projects/<id>. A bare first segment containing a colon is rejected as ambiguous URI syntax; a colon after an explicit leading slash or in a later segment remains opaque path data. Absolute and scheme-relative URLs, query or fragment markers, trailing slashes, and empty segments fail locally. Put query parameters in --query key=value (repeatable); values may be empty or contain commas and equals signs, and repeated values retain their order.

Build a JSON body with --field key=value (repeatable), pass any valid JSON value with --body '<json>', or read one with --body-file <path>. Use --body-file - to read from stdin. These body modes are mutually exclusive, and duplicate --field keys fail locally. A PATCH with no body sends no Content-Type and no JSON null body.

Every real PATCH sends an idempotency key so a retried request is not applied twice. A key is generated automatically; pass --idempotency-key <key> to supply your own (1-255 visible ASCII bytes). Key values are sensitive: output reports only whether a key is generated or explicit and never prints the value. Use --dry-run to preview the method, path, query, body, and idempotency behavior without resolving credentials or contacting the API.

PATCH is an unsafe raw action and does not ask for confirmation. Choosing this leaf is the explicit decision to send it; --force is not required.

By default the decoded "data" value of the API success envelope is printed. Use --raw to print the full success envelope, including data, meta, request_id, and unknown envelope keys. --raw and --dry-run cannot be combined.

Mark a request value as sensitive with --secret-field <name> (repeatable). Named query values, field values, and matching JSON body keys are shown as [REDACTED] in dry-run previews, --debug output, and rendered errors; the flag does not add a request value.

JSON output is the selected machine value as stable JSON. Default human and --plain output print scalar values without JSON quotes; objects, arrays, and null print as JSON because the raw shape is not known ahead of time.

--include-meta adds safe transport context under meta when --json, --jq, or --template is selected. The ordinary value moves under data; output without --include-meta remains unchanged. It cannot be combined with --dry-run.

Output modes: default human, --plain, --json stable JSON, and --jq/--template transforms over the selected JSON value.

```text
svanja api patch <path> [flags]
```

Needs a stored key (svanja login) or SVANJA_API_KEY.

| Flag | What it does |
| --- | --- |
| `--body` | JSON request body (mutually exclusive with --field and --body-file) |
| `--body-file` | read the JSON request body from a file, or - for stdin |
| `--dry-run` | preview the request without resolving credentials or contacting the API |
| `--field` | body field as key=value (repeatable; mutually exclusive with --body and --body-file) |
| `--idempotency-key` | explicit idempotency key (1-255 visible ASCII bytes); generated when omitted on replayable unsafe routes |
| `--query` | query parameter as key=value (repeatable) |
| `--raw` | print the full API success envelope instead of only data |
| `--secret-field` | request field name whose value must be redacted in debug output and errors (repeatable) |

```bash
svanja api patch /projects/<id> --field status=active
svanja api patch /projects/<id> --body '{"status":"paused"}' --json
svanja api patch /projects/<id> --body-file payload.json --dry-run
svanja api patch /projects/<id> --field status=active --idempotency-key <key>
svanja api patch /projects/<id> --jq .status
svanja api patch /projects/<id> --field status=active --template '{{.status}}'
svanja api patch /projects/<id> --field status=active --include-meta --template '{{.meta.request_id}}'
svanja api patch /projects/<id> --body '{"token":"<token>"}' --secret-field token --debug
```

### svanja api post

Send a POST request to an API path using the active profile and credential.

<path> is API-relative and is joined below the resolved API base. Give a path like /projects or projects. A bare first segment containing a colon is rejected as ambiguous URI syntax; a colon after an explicit leading slash or in a later segment remains opaque path data. Absolute and scheme-relative URLs, query or fragment markers, trailing slashes, and empty segments fail locally. Put query parameters in --query key=value (repeatable); values may be empty or contain commas and equals signs, and repeated values retain their order.

Build a JSON body with --field key=value (repeatable), pass any valid JSON value with --body '<json>', or read one with --body-file <path>. Use --body-file - to read from stdin. These body modes are mutually exclusive, and duplicate --field keys fail locally. A POST with no body sends no Content-Type and no JSON null body.

Replayable POST routes send an idempotency key so a retried request is not applied twice. A key is generated automatically; pass --idempotency-key <key> to supply your own (1-255 visible ASCII bytes). Key values are sensitive: output reports only whether a key is generated, explicit, or suppressed and never prints the value.

Generated idempotency and automatic retry are suppressed for v1 routes that return one-time plaintext secrets: /api-keys and /api-keys/{api_key_id}/rotate. An explicit --idempotency-key is still validated and sent as advanced user intent, but the server may reject it and the CLI still makes only one attempt for those routes.

Use --dry-run to preview the method, path, query, body, idempotency behavior, and any non-replayable retry policy without resolving credentials or contacting the API.

POST is an unsafe raw action and does not ask for confirmation. Choosing this leaf is the explicit decision to send it; --force is not required.

By default the decoded "data" value of the API success envelope is printed. Use --raw to print the full success envelope, including data, meta, request_id, and unknown envelope keys. --raw and --dry-run cannot be combined.

Mark a request value as sensitive with --secret-field <name> (repeatable). Named query values, field values, and matching JSON body keys are shown as [REDACTED] in dry-run previews, --debug output, and rendered errors; the flag does not add a request value.

JSON output is the selected machine value as stable JSON. Default human and --plain output print scalar values without JSON quotes; objects, arrays, and null print as JSON because the raw shape is not known ahead of time.

--include-meta adds safe transport context under meta when --json, --jq, or --template is selected. The ordinary value moves under data; output without --include-meta remains unchanged. It cannot be combined with --dry-run.

Output modes: default human, --plain, --json stable JSON, and --jq/--template transforms over the selected JSON value.

```text
svanja api post <path> [flags]
```

Needs a stored key (svanja login) or SVANJA_API_KEY.

| Flag | What it does |
| --- | --- |
| `--body` | JSON request body (mutually exclusive with --field and --body-file) |
| `--body-file` | read the JSON request body from a file, or - for stdin |
| `--dry-run` | preview the request without resolving credentials or contacting the API |
| `--field` | body field as key=value (repeatable; mutually exclusive with --body and --body-file) |
| `--idempotency-key` | explicit idempotency key (1-255 visible ASCII bytes); generated when omitted on replayable unsafe routes |
| `--query` | query parameter as key=value (repeatable) |
| `--raw` | print the full API success envelope instead of only data |
| `--secret-field` | request field name whose value must be redacted in debug output and errors (repeatable) |

```bash
svanja api post /projects --field name=Demo --field status=active
svanja api post /projects --body '{"name":"Demo","status":"active"}' --json
svanja api post /projects --field name=Demo --json --include-meta
svanja api post /projects --body-file payload.json --dry-run
svanja api post /projects --field name=Demo --idempotency-key <key> --json
svanja api post /projects --field name=Demo --jq .id
svanja api post /projects --field name=Demo --template '{{.id}}'
svanja api post /projects --field token=<token> --secret-field token --debug
```

### svanja api

Call public API endpoints directly when a first-class command is not available. Paths are confined below the resolved API base, and command leaves reuse the active profile, credential, locale, retry, error, and output behavior. Raw POST suppresses generated idempotency and automatic retry for documented v1 routes that return one-time plaintext secrets.

```text
svanja api [flags]
```

Works without a key.

```bash
svanja api get /whoami
svanja api post /projects --field name=Demo
```
