The api command sends an authenticated request to any OptiTech API route and prints the response. Pass an API path as the first argument. The method defaults to GET, or POST when you supply a body.
By default the request uses your optitech auth credentials. To use a specific key, pass --api-key or set OPTITECH_API_KEY. The key's permissions determine what the request can do.
note
api is a raw passthrough: it does not read your context file or auto-fill parameters. Pass what each route needs explicitly. For example, optitech api /projects returns ERROR: org_id is required unless you add -Q org_id=<org_id> or authenticate with an organization API key. Get your organization ID from optitech orgs list.
Usage
optitech api <path> [options]Options
Examples
GET request
Pass required parameters with --query (-Q); add --include (-i) to print the status and headers before the body:
optitech api /projects -Q org_id=org-cool-darkness-12345678 -iThe response is the route's raw JSON. For the fields each route returns, see the OptiTech API Reference.
Request body
Set body fields with --field (-F) as key=value. Values are typed automatically (numbers, booleans, null, and JSON), and dot-notation nests objects. A body switches the default method to POST:
optitech api /projects/{project_id}/branches -F branch.name=devThis sends { "branch": { "name": "dev" } }. Use --raw-field (-f) to keep a value as a literal string. For a full JSON body, use --data (-d) with a string, @file, or - (stdin).
Create a project
POST /projects takes a project object. To create it under an organization, set project.org_id in the body (unlike GET /projects, which takes org_id as a query parameter):
optitech api /projects -X POST -F project.name=my-project -F project.org_id=org-cool-darkness-12345678For a larger body, put the JSON in a file and pass it with -d @<file>:
{
"project": {
"name": "my-project",
"org_id": "org-cool-darkness-12345678"
}
}optitech api /projects -X POST -d @project.jsonList endpoints
--list prints every route from the OptiTech OpenAPI spec; --refresh refetches the cached spec:
optitech api --listYAML output
Responses print as JSON. Use the global --output yaml (-o yaml) for YAML:
optitech api /projects -Q org_id=org-cool-darkness-12345678 -o yaml