Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub API - "Get contents" continually returning 404 for valid path

I'm using probot => https://probot.github.io/

I've been developing a GitHub application that analyses a specific .json file in a repo for changes to date strings. I do this by subscribing to the push event and watching it with a webhook.

I am using request in Node. The issue I am having is that I continually receive a 404 when the hook runs. My code looks like this:

app.on('push', async context => {
    let repoOwner = context.payload.repository.owner.name;
    let repoName = context.payload.repository.name;

    const options = {
      url: `https://api.github.com/repos/${repoOwner}/${repoName}/contents/file.json`,
      headers: { 'User-Agent': 'request' }
    }
    request.get(options, (error, response, body) => {
      console.log(body) // logs {message: 'Not Found', documentation_url:... etc
      })
  })

previously I was not including a user-agent header which was constantly returning a 403 - GitHub's api specifies that you must pass a header. After doing this I am now constantly getting this 404

like image 595
captainrad Avatar asked Dec 22 '25 02:12

captainrad


1 Answers

Possible reasons for a 404:

  • the repository is private and you don't have access (that would require a header "Authorization: token $TOKEN")
  • The JSON response (since the default answer is a JSON with the file contents encoded in base64) exceed 1MB. The Get Contents API does mention "This API supports files up to 1 megabyte in size."
    Using a header "Accept: application/vnd.github.3.raw" would give you the raw content.
like image 171
VonC Avatar answered Dec 23 '25 15:12

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!