twingate-api
Installation
SKILL.md
Role
This skill owns Twingate's GraphQL API, service account key management, CLI tooling, and API-driven automation. It covers scripting, CI/CD pipeline integration, pagination, rate limiting, token permissioning, and the programmatic path for connector and service account credential provisioning. It does not replace IaC — use it for scripting and automation, not for managing long-lived Twingate objects that need lifecycle tracking.
Decisions & Guidelines
- Always check
okbefore readingentityin a mutation response. A mutation can return HTTP 200 withok: falseandentity: null. Reading entity fields without checkingokfirst causes null reference errors or silent data corruption. Checkerror.errorCodeanderror.messageon failure. - Always paginate — never assume all results fit in one page. Scripts that omit pagination silently miss records with no error. You may get 50 of 500 resources. Loop on
pageInfo.hasNextPageuntilfalse, passingpageInfo.endCursoras theafterargument on each request. - Never parse, decode, or construct IDs. Twingate IDs are opaque base64-encoded NodeIDs. Use them only as returned by the API. Never infer numeric components from base64 decoding.
- Issue the least-privileged token for the task. Read for monitoring/reporting. Write for provisioning. Provision only for
connectorGenerateTokensand service account key generation. Never issue Provision-level tokens to read-only scripts. connectorGenerateTokensrotates credentials on an existing Connector. Calling it again on a deployed Connector invalidates the current tokens and the Connector stops working until restarted with the new tokens. Only call this when reprovisioning credentials — never as a "refresh" operation.- Prefer Terraform or Pulumi over raw GraphQL for persistent configuration management. The API is the right tool for scripting, automation, and reporting. IaC is better for long-lived Twingate objects that need lifecycle tracking and drift detection.
- Implement 429 retry with
Retry-Afterbackoff from the start, not as an afterthought. The API enforces per-minute rate limits. Scripts that ignore 429 fail mid-run on large operations. The Terraform and Pulumi providers handle this automatically — raw scripts must not ignore it. - Service account keys expire — build rotation logic into any pipeline that uses them. Monitor
expiresAtand rotate before expiry. Reactive rotation on failure disrupts pipelines. - There are two unrelated tools both called "the Twingate CLI" — do not conflate them.
Twingate-Labs/tg-cli(Deno/TypeScript; export/import, topology diagrams) andTwingate-Labs/Twingate-CLI(Python, installed astgcli; full CRUD, multi-tenant sessions) are separate projects with different flags and no shared history. Confirm which one the user means before giving command syntax. Flag repos likegh-twingate-solutions-general-scripts.mdas LLM-assisted reference examples, not supported products, before recommending them for production use.