gh api Call the GitHub API directly
Makes an authenticated request to the GitHub API and prints the response. Use it for anything gh has no dedicated command for, or to script against the API without managing tokens.
Synopsis
gh api ENDPOINT [FLAGS]
Common options
| Option or form | What it does |
|---|---|
-X, --method METHOD | HTTP method such as GET (default), POST, PATCH or DELETE |
-f, --raw-field KEY=VALUE | Add a text field to the request |
-F, --field KEY=VALUE | Add a field, converting numbers and true/false, or @file |
-q, --jq EXPR | Filter the JSON response |
--paginate | Fetch every page of results |
-H, --header "K: V" | Add a request header |
Examples
gh api user --jq .login
octocat
gh api repos/octocat/Hello-World --jq .stargazers_count
gh api repos/octocat/Hello-World/issues --paginate --jq ".[].title"
gh api repos/octocat/Hello-World/issues/12/comments -f body="Thanks, fixed."
gh api graphql -f query='{ viewer { login } }'
Notes
- {owner} and {repo} in an endpoint are filled in from the current repository: gh api repos/{owner}/{repo}/releases.
- Adding a field switches the method to POST unless you set -X.
- Quote anything the shell might change, such as { } or *, and check the method before writing.
See also
Last reviewed 2026-10-09.