Home > Blockchain >  Why reading pull request data using github cli api causes "gh: Not Found (HTTP 404)" error
Why reading pull request data using github cli api causes "gh: Not Found (HTTP 404)" error

Time:07-17

When using the enter image description here

CodePudding user response:

I decided to answer my own question because it took me several hours to realize the solution to this and I couldn't find it anywhere online. Basically, the reason this happens is purely due to the way the path is written. If you remove the / from before the word 'repos' then the command works perfectly well both on PowerShell, wsl and git-bash terminals.

So the correct script should be:

# GitHub CLI api
# https://cli.github.com/manual/gh_api

gh api \
  -H "Accept: application/vnd.github json" \
  repos/OWNER/REPO/pulls/PULL_NUMBER

Again, this is different than what is officially written in the GitHub API documentation because I removed the / before the word 'repos'. I hope this helps others as well.

CodePudding user response:

While the gh code sample in the REST API does have an extra / prefix, the actual gh api man page does not:

Examples:

# list releases in the current repository
$ gh api repos/{owner}/{repo}/releases

# post an issue comment
$ gh api repos/{owner}/{repo}/issues/123/comments -f body='Hi from CLI'

Placeholder values "{owner}", "{repo}", and "{branch}" in the endpoint argument will get replaced with values from the repository of the current directory or the repository specified in the GH_REPO environment variable.

Note that in some shells, for example PowerShell, you may need to enclose any value that contains "{...}" in quotes to prevent the shell from applying special meaning to curly braces.

  • Related