Any API request
source-coop api sends a request to /api/v1 as you, and prints the response. Use it for what the other commands do not do.
source-coop api products/my-org -q limit=5
source-coop api products/my-org -f product_id=new -f title="New" -f description="" \
-f visibility=public -f data_connection_id=my-connection
source-coop api products/my-org/new -X PATCH -F changes.json -f title="Renamed"
echo '{"title": "Renamed", "tags": ["a"]}' | source-coop api products/my-org/new -X PATCH -F -
| Flag | Does |
|---|---|
-q key=value |
Adds a query parameter. |
-f key=value |
Sets a field in the JSON body. A value that is valid JSON (5, true, null, ["a","b"]) is sent as JSON. Other values are strings. To send a JSON-like value as a string, quote it: -f product_id='"2024"'. |
-F file.json |
Reads the body from a file (- for stdin). -f fields replace its keys. |
-X METHOD |
Sets the method. The default is GET, or POST with a body. A GET has no body. |
The path is always under /api/v1. A query string in the path is kept. The API's OpenAPI spec at https://source.coop/api/openapi lists the paths and their fields.
api prints the response body on stdout as the API sent it, so it does not accept --json. It also prints error responses there. If the status is not a success, the exit code shows the type of error (see Exit codes).
Public data needs no sign-in. Other requests use the session from source-coop auth login, with an access token for the API (--audience, default https://source.coop). The CLI renews this token when necessary. If SOURCE_TOKEN is set, the CLI sends it instead. To use a different deployment, such as http://localhost:3000, set --api-url (or SOURCE_API_URL).
api: any request to the API