Search code examples
github-apirepositorygithub-organizations

Retrieve all the non-forked repos from a organization with Github API


Using Github's API, I'm trying to retrieve a list of the all sources repositories from a organization with hundreds of repositories: Github API

Pagination is not a problem. Using a query like:

curl https://api.github.com/orgs/:org/repos?page=X

Where X is the number of the page, it works fine, but what I need is to retrieve just the non-forked (or sources) repositories, so for this purpose I'm trying this query:

curl https://api.github.com/orgs/:org/repos?type=source?page=X

Using this, it retrieves the sources repositories from the first page, but it doesn't receive the X paramenter at all (as it always return the same repositories using different numbers).

My guessing is that this query just accepts one parameter but, is there any way to do this without using Octokit?


Solution

  • The pagination feature works perfectelly fine within the Github API but the main issue with your HTTP url and which makes request not paginated is that the type query parameter is not taken into account when your request is processed and that is simply because you have chosen to ommit it with the ? character.

    You URL is with a wrong format and more specifically you have devined two Query Strings because you used the ? character twice:

    • ?type
    • ?page

    You should take a look to the link above pointing to Query Strings format in a Unified Resource Locator, and simply said you have two rules to follow:

    • When you type an interrogation character ?, this means that you are going to provide a set of query paramters.
    • Query parameters are separated by an ampersand character &

    Putting above liners in action, you request URL should be:

    curl https://api.github.com/orgs/:org/repos?type=sources&page=X