Linux command
gh-api 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Make GET request
gh api [/repos/owner/repo]
Make POST request
gh api -X POST [/repos/owner/repo/issues] -f title="[title]"
With JSON body
gh api [/endpoint] --input [data.json]
Use GraphQL
gh api graphql -f query='[query]'
Paginate results
gh api [/endpoint] --paginate
Output specific field
gh api [/repos/owner/repo] --jq '.[field]'
说明
gh api makes authenticated HTTP requests to the GitHub API. Supports both REST and GraphQL APIs with automatic authentication.
参数
- -X, --method _method_
- HTTP method.
- -f, --raw-field _key=value_
- Add a string parameter.
- -F, --field _key=value_
- Add a typed parameter (non-string values, file references with @, booleans, null).
- --input _file_
- Read body from file.
- --jq _query_
- Filter JSON output.
- --paginate
- Fetch all pages of results.
- --slurp
- With --paginate, combine all pages into a single JSON array.
- -i, --include
- Include HTTP response headers in the output.
- -p, --preview _name_
- Opt into a GitHub API preview feature.
- -H, --header _header_
- Add HTTP header.
- -t, --template _template_
- Format output with a Go template.
- --hostname _host_
- Make request against a specific GitHub hostname (for GHES).
- --cache _duration_
- Cache the response (e.g., 1h, 30m).
FAQ
What is the gh-api command used for?
gh api makes authenticated HTTP requests to the GitHub API. Supports both REST and GraphQL APIs with automatic authentication.
How do I run a basic gh-api example?
Run `gh api [/repos/owner/repo]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -X, --method _method_ do in gh-api?
HTTP method.