Home > OS >  How to access newly created files on a repo via the Github API?
How to access newly created files on a repo via the Github API?

Time:02-03

I can access existing files just fine. For example, this works perfectly to retrieve the contents of README.md at the root of the repo:

https://api.github.com/repos/kevindecent/decent-salesforce/contents/README.md

However, if I create a new file at the root of the repo called 'test.txt', I get a 'Not Found' error when I try to retrieve it like so:

https://api.github.com/repos/kevindecent/decent-salesforce/contents/test.txt

Why can't I access newly created files at the root of the repo, using the Github API? Is my access token corrupt or something?

CodePudding user response:

Turns out I was making a simple mistake. I was returning the contents of a forked version of the repo using this URL:

https://api.github.com/repos/<Github User Name>/decent-salesforce/contents

When I should've returned the contents at the organization level using this URL:

https://api.github.com/repos/<Github Organization Name>/decent-salesforce/contents

CodePudding user response:

Double-check your PAT (Personal Access Token), and its associated scope (at least repo), as well as its possible expiration date.

Use said token directly in command-line to see what is going on:

curl -v -i -u your_username:$token https://api.github.com/...
  •  Tags:  
  • Related