Git is the most popular revision control application and GitHub is a hosting service for git repositories, recently GitHub launch a new Rest API v3.0 and published on its official website.

You can access all Schema of Rest API URLs from here. This tutorial help to access GitHub rest call using rest client.

I am using the guzzle PHP rest client to access rest call and API supports Cross Origin Resource Sharing (CORS) for AJAX requests from any origin.

first of all, I will list down all available rest endpoints,

"current_user_url": "",
"current_user_authorizations_html_url": "{/client_id}",
"authorizations_url": "",
"code_search_url": "{query}{&page,per_page,sort,order}",
"commit_search_url": "{query}{&page,per_page,sort,order}",
"emails_url": "",
"emojis_url": "",
"events_url": "",
"feeds_url": "",
"followers_url": "",
"following_url": "{/target}",
"gists_url": "{/gist_id}",
"hub_url": "",
"issue_search_url": "{query}{&page,per_page,sort,order}",
"issues_url": "",
"keys_url": "",
"notifications_url": "",
"organization_repositories_url": "{org}/repos{?type,page,per_page,sort}",
"organization_url": "{org}",
"public_gists_url": "",
"rate_limit_url": "",
"repository_url": "{owner}/{repo}",
"repository_search_url": "{query}{&page,per_page,sort,order}",
"current_user_repositories_url": "{?type,page,per_page,sort}",
"starred_url": "{/owner}{/repo}",
"starred_gists_url": "",
"team_url": "",
"user_url": "{user}",
"user_organizations_url": "",
"user_repositories_url": "{user}/repos{?type,page,per_page,sort}",
"user_search_url": "{query}{&page,per_page,sort,order}"

Project Rest End Points

Route Method Description
/projects GET Get all projects
/projects/visible GET Get a list of projects which the authenticated user can only see.
/projects/:id GET Get specific project details by project Id.
/projects POST Create a new Project.
/projects/user/:user_id POST Create a new Project only for specific users.
/projects/:id PUT Updated project by project ID.

Repository Rest End Points

Route Method Description
/projects/:id/repository/tree GET Get all repositories of the specific project
/projects/:id/repository/archive GET Get an archive of the repository.
/projects/:id/repository/contributors GET Get all contributors of the specific repositories.

Repository Branch Rest End Points

Route Method Description
/projects/:id/repository/branches GET Get a list of repository branches from a project
/projects/:id/repository/branches/:branch GET Get details of a single repository branch.
/projects/:id/repository/branches POST Create a new repository branch.
/projects/:id/repository/branches/:branch DELETE Delete the repository branch.

List repository commits Rest Api

Route Method Description
/projects/:id/repository/commits GET Get a list of commits from a project repository
/projects/:id/repository/commits POST Create a commit on the repository branch.
/projects/:id/repository/commits/:sha GET Get single commit details.

Users Rest API

Route Method Description
/users GET Get a list of users
/users/:id GET Get single user details.
/users POST Create a new user.
/users/:id PUT Update user by userId.
/users/:id DELETE Delete user by userId.

How to pass parameters into GitHub Rest call using Curl

curl -i ""

How to access the above rest call using Guzzle PHP rest client,

Read: Simple Example and Demo of Guzzle

GitHub provides many rest clients that need to use authentication tokens, so access that rest endpoints user must be authorized. GitHub provides three types of user authentication processes.

Basic Authentication

curl -u "username"

OAuth2 Token (sent in a header)

curl -H "Authorization: token OAUTH-TOKEN"

OAuth2 Token (sent as a parameter)


This is a very simple process of authentication, Rest needs a GitHub token to validate user authorization. You can get more information from here

Simple Example to get All project Using Github Private Token

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">require_once 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client([
// Base URI is used with relative requests
'base_uri' => '',
// You can set any number of default request options.
'timeout'  => 2.0,
'headers' => ['Content-Type' => 'application/json', "Accept" => "application/json", "PRIVATE-TOKEN" => 'avxfskkslpopisaw'],
//ssl false
'verify' => false
$response = $client->request('GET', '/projects');
echo "</pre>
<!-- /wp:preformatted -->
<!-- wp:preformatted -->
<pre class="wp-block-preformatted">";
echo $response->getBody();
<!-- /wp:preformatted -->

I have passed the private token on "PRIVATE-TOKEN" key, You can get your private token by registering apps into git.

Genislab Technologies

NexGeneration complete end-2-end software testing & modern development operations tooling & solutions

Do you want to discuss your testing requirements with us? please don’t hesitate to hit the contact us button below, and we will get back to you at our earliest..