Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 3

Api get content of file for organization repository

Solved! Go to Solution.

I am writing a java program that retrieves file contents from our github repository. In reading github documentaion to retrieve a file i must hit this github endpoint 

GET /repos/:owner/:repo/contents/:path 

 the question I have is what to substitute for owner.  Let's say my personal github user is mike but the owner of the github repository is acme. The first GET path pasted below works in my program. I am able to retrieve the file content with no issues. If I try to substitute mike for acme the path below does not work. I understand why it is not successful because that url path does not exist in github. Does that mean the API token I generate for mike cannot be used to retrieve the content in the repository owned by acme? Or can I retrieve content using the mike api token even though mike is not the owner for the acme repository (but has access to it)? The repository in question "java-repo" that has many contributors. Does this mean there can only be one user that accesses the repository in this case acme via the api's?


GET /repost/acme/java-repo/contents/ -- works

GET /repost/mike/java-repo/contents/ -- does not work

2 Replies
Message 2 of 3

Re: Api get content of file for organization repository

Hi @mapayares,


Thanks for being part of the GitHub Community Forum! I'll do my best to help. 



is always going to be the individual or organization that actually owns the repository in question. The second URL you shared doesn't work, as you noted, simply because the content doesn't exist on your `mike` account. The URL is essentially invalid.

Additionally, API tokens are scoped to your user account. So, if your user account has only read access to the `acme` repository, then your API token can be granted at most read only access by applying the correct scopes. So, at most, the program can only do things that your `mike` account can do, but you can also restrict the program to fewer abilities, depending on how you generate the token.

I hope this helps! 

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

Copilot Lvl 2
Message 3 of 3

Re: Api get content of file for organization repository

thank you so much for your help. i was able to confirmed that it works as you described. thanks again