Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

rowansmithau
Copy link
Contributor

continuation of #19027.

Adds a new 'coder api' command designed to help with querying the various API endpoints via the CLI.

JSON outputs are coloured and use an adapted implementation of https://github.com/cli/cli/blob/trunk/pkg/jsoncolor/jsoncolor.go (MIT)

coder@lime-chimpanzee-83:~/coder$ ./coder api -h
coder v0.0.0-devel

USAGE:
  coder api [flags] <api-path>

  Make requests to the Coder API

  Make an authenticated API request using your current Coder CLI token.
  
  Examples:
    coder api workspacebuilds/my-build/logs
  This will perform a GET request to /api/v2/workspacebuilds/my-build/logs on the connected Coder server.
  
    coder api users/me
  This will perform a GET request to /api/v2/users/me on the connected Coder server.
  
  Consult the API documentation for more information - https://coder.com/docs/reference/api.

OPTIONS:
      --color auto|always|never, $CODER_COLOR (default: auto)
          Output colorization: auto, always, never.

———
Run `coder --help` for a list of global options.
coder@lime-chimpanzee-83:~/coder$ ./coder api users/me
{
  "avatar_url": "https://lh3.googleusercontent.com/a-/ALV-UjV-W8Vr2V-fvRZZtgkBq96FZNWDNheSVE-4Fft_rTGgfDrwuo_1hophRKAxn_q5PY8kQONC_Rr1S0JpF0y44khnwFP70Kkny626bHPCZEZ6uH8sBybdGVL8AuOrwLF_tcjyrKK7K5W3yHXG7mqHEvJdWA6LjfdyWpYZDSuvIajLH845qDXnmGPsZHon3VQ-fp12xwD18LuDTXGRjNkW0H3X-ynX33agWGd1PlPjcaXUZnFsR8SQv6wcQ3mSnqlB96j9g6ji4fl6k7Xi7h_gS6h72t54G7C0jnV9h8_7xco1JgR6Ke1RSPK81kYBw1JE-7KqogMUjaEcMkIZkDw0ptYGCY2O8crK4cyvnf6cvJKeDW8H2gL_p9FcyiIYq40hbIvGz-9lLLdSMoDHlIHy-1bbM5d08WORu4tXvnec3kd7pImrGmZM8ORasnmESeK3TwCeEtE9RXdR4N8EKjPrFzIjfEnA7WMUN-xOMAeklMUyvxsxASepnca9v1yf_18VNM-SG1_9gN1v3uMJ1CpECeh3UxRbPtftcMlNuzZ1n-BUytOXSIXUi_uelz4Na2Hvc5rYJ0lyYWOCf0g1RU5SOVNdZm2xhgG1FygnVp8N4lfq9_MTOGvKuKJeEinnkKFK0N9F4xiUQcgJcRz8QexDMqfgMy8bquNX_wx9W0SHoy2eBDE2LqbbKu_7fezvoBelXPeFFYVRJ-XYek34pWqj7rLyKUMzvCPIexCSKirxL_0qaIR81pvGcqw2I4dgYR6a5rSSRUQ1G6lHitWHEojtFyXNOGbHv4Eh9BHysUkl2ssPWZD8cHQPRogPdQDqi1jpveLueuPMB-bOsxInTlVOS_wSy2KZ_KrP52tr36x-NzXRASvKwR7oFZ6orEhfnsJUJ4-KhMTDxRLo3jG_hxeafZW8zXafL9R7mO7b2ZP7QaegzTF1fKPLUvAs8lSf8FIk2IASbxtI6AZvBceBw4qKY6dzx-q3=s96-c",
  "created_at": "2025-08-04T23:27:42.966958Z",
  "email": "[email protected]",
  "id": "fe50748f-0372-457f-b2ae-1e20a188e2f5",
  "last_seen_at": "2025-09-12T00:57:13.737094Z",
  "login_type": "oidc",
  "name": "Rowan Smith",
  "organization_ids": [
    "703f72a1-76f6-4f89-9de6-8a3989693fe5"
  ],
  "roles": [],
  "status": "active",
  "updated_at": "2025-09-12T00:57:13.737095Z",
  "username": "rowan"
}
coder@lime-chimpanzee-83:~/coder$ ./coder api debug/health/settings
Encountered an error running "coder api", see "coder api --help" for more information
error: API error: 403 Forbidden                                                                                                                                                                                                          
{"message":"Forbidden.","detail":"You don't have permission to view this content. If you believe this is a mistake, please contact your administrator or try signing in with different credentials."}

If you have used AI to produce some or all of this PR, please ensure you have read our AI Contribution guidelines before submitting.

This is a Blink assisted PR.

@rowansmithau rowansmithau self-assigned this Sep 12, 2025
@rowansmithau rowansmithau added the cli Area: CLI label Sep 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Area: CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant