Management API commands
Commands for sending requests to any Management API endpoint from the Knock CLI.
knock mapi <path> [flags]
#Send an authenticated request to any Management API endpoint and print the JSON response. The command uses the same login, service token, environment, and branch as every other CLI command, so you can reach endpoints that don't have a dedicated command.
Pass the endpoint's path relative to /v1, such as /tags or /sources/stripe/logs. A leading /v1 is accepted, so you can copy paths from the Management API reference as written. The path must stay under /v1: full URLs, . and .. segments, encoded slashes, and # fragments are rejected.
The method defaults to GET, or POST when you pass a body with --field, --raw-field, or --input. Set it with --method.
Request bodies
Build a JSON body from key=value pairs, or read it from a file:
- Typed fields.
--field(-F) parsestrue,false,null, and integers. A value of@filereads the contents of a file, and@-reads stdin. - String fields.
--raw-field(-f) always sends the value as a string. - A JSON file.
--inputreads the whole body from a file, or from stdin when you pass-. It can't be combined with--fieldor--raw-field.
Use name[key] to set a nested key, and name[] to append to an array. On a GET request, fields are sent as query params instead of a body.
Output and exit codes
The command prints the response body to stdout, formatted for reading in a terminal and as compact JSON otherwise. It exits with code 1 for any response outside the 2xx range, and prints the method, path, and status to stderr.
To print the request without sending it, pass --dry-run, or --curl for a curl command you can run yourself. The curl command reads your token from the KNOCK_SERVICE_TOKEN environment variable rather than including it. Neither --curl nor --describe needs you to be logged in.
Pagination
Pass --paginate on a GET request to a list endpoint to follow page_info.after and print every entry in one list. The command fetches at most 50 pages unless you raise the limit with --max-pages. When it stops at the limit, or a page fails, it prints the entries it has and the after cursor to pass on your next run to carry on. A failed page also exits with code 1.
Confirmation
The command asks you to confirm before it sends a request that can't be undone: deletes, archives, one-way actions (commit, promote, revert, send, run, cancel, discard, and reset), and writes with commit=true. Pass --force to skip the prompt. You must pass it when you run the command outside an interactive terminal, such as in CI. Otherwise the command exits with an error.
Branches
If you've enabled environments and you're working on a branch, the command sends the branch from your .knockbranch file only to endpoints that take one. A branch you pass with --branch, with --param, or in the path is always sent.
Set the environment or branch once. Passing either one with both its flag and a query param exits with an error.
Flags
The HTTP method: GET, POST, PUT, PATCH, or DELETE. Defaults to GET, or POST when you pass a body.
A typed body field as key=value. Parses true, false, null, and integers. @file reads a file and @- reads stdin. Repeatable.
A string body field as key=value. Repeatable.
A file to read the JSON request body from, or - for stdin. Can't be combined with --field or --raw-field.
A query param as key=value. Repeatable.
An extra request header as Name: value. The CLI sets Authorization, Host, and X-Knock-Client-Id, and they can't be overridden. Repeatable.
Sent as the environment query param. When omitted, the account's default environment is used.
The branch to use. Defaults to the main branch.
Sent as the limit query param, which sets the page size.
Follows page_info.after to fetch every page, and prints one combined list of entries. GET only.
The most pages --paginate fetches. Requires --paginate. Defaults to 50.
Prints the response status and headers before the body.
Prints compact JSON, even in a terminal.
Prints only the response body as compact JSON, for scripts. Can't be combined with --include.
Prints nothing. The exit code says whether the request succeeded. Can't be combined with --include or --verbose.
Prints the request and response details to stderr, with the token redacted.
Prints the request that would be sent, without sending it.
Prints the request as a curl command, without sending it. The token is left as $KNOCK_SERVICE_TOKEN. Can't be combined with --dry-run or --paginate.
Shows the endpoint's params, body, and scope from the Management API's OpenAPI spec, without sending a request.
Fetches the OpenAPI spec again instead of using the cached copy.
Skips the confirmation prompt for requests that can't be undone. Required when running outside an interactive terminal. Defaults to false.
knock mapi list [flags]
#List every Management API endpoint you can call with knock mapi, grouped by tag. The list comes from the Management API's OpenAPI spec, which the CLI fetches and caches for a day. Pass --refresh to fetch it again.
The spec is public, so knock mapi list works before you log in.
Flags
Only show endpoints with this tag. Case-insensitive.
Only show endpoints whose path, summary, or operation ID contains this text.
Fetches the OpenAPI spec again instead of using the cached copy.
Format output as json.