Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

GitHub API returning 404 although resource exists

I'm trying to send a POST request to the GitHub API to submit a comment on a commit.

According to the documentation, all that's needed (other than the URL params) is the body.

I have modified the example from the docs to the following:

curl 
  -X POST 
  -H "Accept: application/vnd.github.v3+json" 
  https://api.github.com/repos/dchacke/test/commits/9b7413350932dd3f2906c0fdd26106c35c7ce450/comments 
  -d '{"body":"test comment"}'

That should post a test comment to this commit. I know the commit and the owner and repo exist (it's my repo and I can see the commit under that URL), and yet I'm getting a 404 with the following response body upon submitting that API request:

{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest/reference/repos#create-a-commit-comment"
}

The documentation makes no mention of authentication being required for that endpoint. A 404 doesn't exactly sound like an authentication problem, but just in case GitHub doesn't want to confirm the existence of repos/commits to unauthenticated users (though they do let them see those things on their website...), I tried setting a personal access token in an additional Authorization header in my CURL request. No dice.

What am I doing wrong?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Authentication was the issue after all. I had to make sure I used a token with the right privileges. In this case, it needed the public_repo privilege, which can be set up here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...