I'm looking for a way to read contents of file from a specific commit hash using the GitHub APIs. It’s written in the official documentation that the refs are commits/branch/tags to be used to get contents of a specific file from a specific commit. https://developer.github.com/v3/repos/contents/#get-contents
But the endpoint returns 404. I have the access token and authorization for the repository. The commit hash is also correct and I verified it with git log.
Is there a different solution for this?
You haven't shown us your code, so it's hard for us to say, but I've verified that this API endpoint does indeed work as expected. For example, I ran the following command against the git/git repository and got a response:
$ curl https://api.github.com/repos/git/git/contents/README.md?ref=274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925
If you're seeing a 404, then either (a) the endpoint you're using doesn't exist, whether that's because you have the wrong repo, the wrong API URL, the wrong commit (and this needs to be a commit hash, not a tag hash), or something similar; or (b) your authentication is wrong. To check your authentication, you can try accessing https://api.github.com/user, which will return the current user iff you are properly authenticated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With