CLI guide
GitHub

Scripts and AI agents

source-coop --help ends with a summary of this section. The --help of each command shows its flags and examples. Thus an AI agent can learn the CLI from the CLI.

Output

JSON

These commands accept --json:

Commands that change data print the record after the change. service-account edit --json prints the account as view --json does.

With --json:

These commands do not accept --json, because their output is already for machines: creds (--format), auth token (a token), api (the API's response), completions (a shell script) and service-account usage (a workflow or shell exports). auth login does not accept it either, because it uses the browser. Use auth status --json after it.

With --json, an error is also JSON, on stderr. If the error came from the API, it contains the data of the API's RFC 9457 problem:

{"error": {"code": "invalid", "message": "…", "status": 400, "field_errors": {"title": ["…"]}, "type": "https://source.coop/api/problems/invalid", "request_id": "…"}}

Exit codes

All commands use the same exit codes:

Code Meaning
0 Success
1 Other failure, including a cancelled prompt
2 Incorrect command-line usage
3 The API refused the input (HTTP 400, 409, 422). Correct the named fields and try again.
4 Not signed in, or not allowed (HTTP 401, 403)
5 Not found (HTTP 404)
130 Interrupted (Ctrl+C)
Without a terminal: errors, --json, exit codes and -F -

Use the API without signing in

If SOURCE_TOKEN is set, the CLI sends it to the API instead of the session's access token. Thus a script or CI job can use the API without auth login.

Use your session with other tools

auth token prints the session's access token for the source.coop API. If the token has expired, it renews it first.

curl -H "Authorization: Bearer $(source-coop auth token)" https://source.coop/api/v1/...
auth token: the session's access token, for curl

To send a request through the CLI, see Any API request.