feat(cli): add checkly api generic API pass-through command#1320
feat(cli): add checkly api generic API pass-through command#1320martzoukos wants to merge 4 commits into
checkly api generic API pass-through command#1320Conversation
Adds a new `checkly api` command that lets users and AI agents call any Checkly API endpoint directly, with authentication handled automatically. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Address all findings from multi-persona code review: fix silent jq error swallowing, add HTTP status checks on paginated follow-up requests, default --input to POST, guard --paginate on GET-only, fix HTTP/1.1 status line format, extract shared Content-Range parser, replace process.stderr.write with oclif logToStderr, add max-pages guard and entries type validation, and add 401/403 error hints. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
|
||
| Run `npx checkly skills communicate` for the full protocol details. | ||
|
|
||
| ## API Pass-Through (fallback for any endpoint) |
There was a problem hiding this comment.
@stefanjudis I'd appreciate your 2c on this section regarding agent ergonomics.
thebiglabasky
left a comment
There was a problem hiding this comment.
I'd love to discuss a few points before approving. Nothing really blocking, but also, not yet confident we want to go exactly as is
There was a problem hiding this comment.
I was about to propose to move this into api-paginate, but see it's used by the REST client, I guess it's fine. Looks like a tiny file now :)
|
Great feedback @thebiglabasky !
|
- Mark command as destructive (supports PUT/PATCH/DELETE) - Harden URL validation with hostname verification after resolution - Fix cursor pagination to detect nextId alone, supporting both entries and items array fields - Add OpenAPI spec URL alongside docs reference Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Can you show me how you'd do something more complex such as setting a retry strategy for a check or group? |
By doing something like: checkly api /v1/checks/YOUR_CHECK_ID -X PUT --input - <<'EOF'
{
"retryStrategy": {
"type": "LINEAR",
"baseBackoffSeconds": 10,
"maxRetries": 3,
"maxDurationSeconds": 600,
"sameRegion": true
}
}
EOFAre you asking about multi-line parameters in general or about something specific to retries that I'm missing? |
thebiglabasky
left a comment
There was a problem hiding this comment.
The fact this mimics gh makes me pretty confident in the design. I didn't test it locally, but trust that you did. Fine work!
|
@sorccu anything regarding your question above that needs addressing or shall I go ahead and merge it? |
|
Can we delay merging till at least tomorrow? I'd like to think about this a bit. To be clear I'm for the idea, but I'm not sure if our API is ready to be exposed like this |
|
Yeah, that works @sorccu . 👍 |
MegaMaddin
left a comment
There was a problem hiding this comment.
Please check internal discussion in #cli.
Why
The Checkly CLI has dedicated commands for a handful of API endpoints, but the Checkly API has ~150 endpoints total. Today, users and AI agents that need to reach an uncovered endpoint have to fall back to
curlwith manually constructed auth headers — which is error-prone and breaks agent workflows.This is especially important for AI agents: when an agent needs data from an endpoint that doesn't have a CLI command yet, it's stuck. This command gives agents (and power users) an immediate escape hatch — authenticated
curlfor the entire Checkly API, similar to howgh apiworks for GitHub.Linear: AI-132
What changed
New command:
checkly api <endpoint>A generic pass-through that makes authenticated HTTP requests to any Checkly API endpoint. The CLI injects auth headers and the correct base URL automatically.
checkly api /v1/checks checkly api /v1/dashboards -X GET --jq '.[].name' checkly api /v1/checks -X POST -F name=MyCheck -F activated:=trueFlags:
-X/--method— HTTP method (GET, POST, PUT, PATCH, DELETE). Defaults to GET, or POST when fields are present-f— String field parameter (key=value)-F— Typed field parameter (key=valuefor strings,key:=valuefor JSON like booleans/numbers/arrays)-H— Custom HTTP header--jq— Filter JSON output using systemjq(clear error message ifjqisn't installed)--input— Request body from a file path or-for stdin--paginate— Auto-fetch all pages (supports both Content-Range and cursor-based pagination)--include/-i— Show response status and headers--verbose— Print full request/response headers to stderrOutput: Pretty-printed JSON in the terminal, compact JSON when piped (matches
gh apibehavior).AI context / skills update
Updated the Checkly skill file (
SKILL.md) so AI agents knowcheckly apiexists as a fallback. The section points to the Checkly API reference for endpoint discovery — no static endpoint list baked in, so it won't go stale when the backend API changes.Security
https://evil.com/...) and protocol-relative URLs (//evil.com/...) to prevent leaking auth headers to external hosts--jqflag usesexecFile(notexec), so the filter expression is passed as a direct argument to thejqbinary with no shell interpretationNew files
packages/cli/src/commands/api.tspackages/cli/src/helpers/api-fields.ts-f/-Ffield flagspackages/cli/src/helpers/api-paginate.tspackages/cli/src/commands/__tests__/api.spec.tspackages/cli/src/helpers/__tests__/api-fields.spec.tspackages/cli/src/helpers/__tests__/api-paginate.spec.tsManual testing
Requires
CHECKLY_API_KEYandCHECKLY_ACCOUNT_IDset, or a priorcheckly login.Test plan
checkly api --helpoutput./packages/cli/bin/run skills install🤖 Generated with Claude Code