Skip to content
github api v3 in nodejs
Pull request Compare This branch is 238 commits behind pksunkara:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


octonode is a library for nodejs to access the github v3 api


npm install octonode


var github = require('octonode');

// Then we instanciate a client with or without a token (as show in a later section)

var ghme   =;
var ghuser = client.user('pksunkara');
var ghrepo = client.repo('pksunkara/hub');
var ghorg  ='flatiron');
var ghissue = client.issue('pksunkara/hub', 37);
var ghpr ='pksunkara/hub', 37);
var ghgist = client.gist();
var ghteam =;

var ghsearch =;

Build a client which accesses any public information

var client = github.client();

client.get('/users/pksunkara', {}, function (err, status, body, headers) {
  console.log(body); //json object

Build a client from an access token

var client = github.client('someaccesstoken');

client.get('/user', {}, function (err, status, body, headers) {
  console.log(body); //json object

Build a client from credentials

var client = github.client({
  username: 'pksunkara',
  password: 'password'

client.get('/user', {}, function (err, status, body, headers) {
  console.log(body); //json object

Build a client from client keys

var client = github.client({
  id: 'abcdefghijklmno',
  secret: 'abcdefghijk'

client.get('/user', {}, function (err, status, body, headers) {
  console.log(body); //json object

Request Options

Request options can be set by setting defaults on the client. (e.g. Proxies)

var client = github.client();

client.requestDefaults['proxy'] = ''

These options are passed though to request, see their API here:


You can set proxies dynamically by using the example above, but Octonode will respect environment proxies by default. Just set this using: export HTTP_PROXY='' if you are using the command line

Many of the below use cases use parts of the above code


Authenticate to github in cli mode (desktop application)

  username: 'pksunkara',
  password: 'password'
}).login(['user', 'repo', 'gist'], function (err, id, token) {
  console.log(id, token);

Revoke authentication to github in cli mode (desktop application)

  username: 'pksunkara',
  password: 'password'
}).revoke(id, function (err) {
  if (err) throw err;

Authenticate to github in web mode (web application)

// Web application which authenticates to github
var http = require('http')
  , url = require('url')
  , qs = require('querystring')
  , github = require('octonode');

// Build the authorization config and url
var auth_url = github.auth.config({
  id: 'mygithubclientid',
  secret: 'mygithubclientsecret'
}).login(['user', 'repo', 'gist']);

// Store info to verify against CSRF
var state = auth_url.match(/&state=([0-9a-z]{32})/i);

// Web server
http.createServer(function (req, res) {
  uri = url.parse(req.url);
  // Redirect to github login
  if (uri.pathname=='/login') {
    res.writeHead(301, {'Content-Type': 'text/plain', 'Location': auth_url})
    res.end('Redirecting to ' + auth_url);
  // Callback url from github login
  else if (uri.pathname=='/auth') {
    var values = qs.parse(uri.query);
    // Check against CSRF attacks
    if (!state || state[1] != values.state) {
      res.writeHead(403, {'Content-Type': 'text/plain'});
    } else {
      github.auth.login(values.code, function (err, token) {
        res.writeHead(200, {'Content-Type': 'text/plain'});
  } else {
    res.writeHead(200, {'Content-Type': 'text/plain'})

console.log('Server started on 3000');

Rate Limiting

You can also check your rate limit status by calling the following.

client.limit(function (err, left, max) {
  console.log(left); // 4999
  console.log(max);  // 5000

API Callback Structure

All the callbacks for the following will take first an error argument, then a data argument, like this:, data, headers) {
  console.log("error: " + err);
  console.log("data: " + data);
  console.log("headers:" + headers);


If a function is said to be supporting pagination, then that function can be used in many ways as shown below. Results from the function are arranged in pages.

The page argument is optional and is used to specify which page of issues to retrieve. The perPage argument is also optional and is used to specify how many issues per page.

// Normal usage of function
ghrepo.issues(callback); //array of first 30 issues

// Using pagination parameters
ghrepo.issues(2, 100, callback); //array of second 100 issues
ghrepo.issues(10, callback); //array of 30 issues from page 10

// Pagination parameters can be set with query object too
  page: 2,
  per_page: 100,
  state: 'closed'
}, callback); //array of second 100 issues which are closed

Github authenticated user api

Token/Credentials required for the following:

Get information about the user (GET /user); //json

Update user profile (PATCH /user)

  "name": "monalisa octocat",
  "email": "",
}, callback);

Get emails of the user (GET /user/emails)

ghme.emails(callback); //array of emails

Set emails of the user (POST /user/emails)

ghme.emails(['', ''], callback); //array of emails
ghme.emails('', callback); //array of emails

Delete emails of the user (DELETE /user/emails)

ghme.emails(['', '']);

Get the followers of the user (GET /user/followers)

ghme.followers(callback); //array of github users

Get users whom the user is following (GET /user/following)

This query supports pagination.

ghme.following(callback); //array of github users

Check if the user is following a user (GET /user/following/marak)

ghme.following('marak', callback); //boolean

Follow a user (PUT /user/following/marak)


Unfollow a user (DELETE /user/following/marak)


Get public keys of a user (GET /user/keys)

ghme.keys(callback); //array of keys

Get a single public key (GET /user/keys/1)

ghme.keys(1, callback); //key

Create a public key (POST /user/keys)

ghme.keys({"title":"laptop", "key":"ssh-rsa AAA..."}, callback); //key

Update a public key (PATCH /user/keys/1)

ghme.keys(1, {"title":"desktop", "key":"ssh-rsa AAA..."}, callback); //key

Delete a public key (DELETE /user/keys/1)


Get the starred repos for the user (GET /user/starred)

This query supports pagination.

ghme.starred(callback); //array of repos

Check if you have starred a repository (GET /user/starred/pksunkara/octonode)

ghme.starred('flatiron/flatiron', callback); //boolean

Star a repository (PUT /user/starred/pksunkara/octonode)'flatiron/flatiron');

Unstar a repository (DELETE /user/starred/pksunkara/octonode)


Get the subscriptions of the user (GET /user/subscriptions)

This query supports pagination.

ghme.watched(callback); //array of repos

List your public and private organizations (GET /user/orgs)

This query supports pagination.

ghme.orgs(callback); //array of orgs

List your repositories (GET /user/repos)

This query supports pagination.

ghme.repos(callback); //array of repos

Create a repository (POST /user/repos)

  "name": "Hello-World",
  "description": "This is your first repo",
}, callback); //repo

Fork a repository (POST /repos/pksunkara/hub/forks)

ghme.fork('pksunkara/hub', callback); //forked repo

Github users api

No token required for the following

Get information about a user (GET /users/pksunkara); //json

Get user followers (GET /users/pksunkara/followers)

This query supports pagination.

ghuser.followers(callback); //array of github users

Get user followings (GET /users/pksunkara/following)

This query supports pagination.

ghuser.following(callback); //array of github users

Get events performed by a user (GET /users/pksunkara/events)

This query supports pagination.['commit_comment'], callback); //array of events

Get user public organizations (GET /users/pksunkara/orgs)

This query supports pagination.

ghuser.orgs(callback); //array of organizations

Github repositories api

Get information about a repository (GET /repos/pksunkara/hub); //json

Get the collaborators for a repository (GET /repos/pksunkara/hub/collaborators)

ghrepo.collaborators(callback); //array of github users

Check if a user is collaborator for a repository (GET /repos/pksunkara/hub/collaborators/marak)

ghrepo.collaborators('marak', callback); //boolean

Get the commits for a repository (GET /repos/pksunkara/hub/commits)

ghrepo.commits(callback); //array of commits

Get a certain commit for a repository (GET /repos/pksunkara/hub/commits/18293abcd72)

ghrepo.commit('18293abcd72', callback); //commit

Get the tags for a repository (GET /repos/pksunkara/hub/tags)

ghrepo.tags(callback); //array of tags

Get the releases for a repository (GET /repos/pksunkara/hub/releases)

ghrepo.releases(callback); //array of releases

Get the languages for a repository (GET /repos/pksunkara/hub/languages)

ghrepo.languages(callback); //array of languages

Get the contributors for a repository (GET /repos/pksunkara/hub/contributors)

ghrepo.contributors(callback); //array of github users

Get the branches for a repository (GET /repos/pksunkara/hub/branches)

ghrepo.branches(callback); //array of branches

Get the issues for a repository (GET /repos/pksunkara/hub/issues)

This query supports pagination.

ghrepo.issues(callback); //array of issues

Create an issue for a repository (POST /repos/pksunkara/hub/issues)

  "title": "Found a bug",
  "body": "I'm having a problem with this.",
  "assignee": "octocat",
  "milestone": 1,
  "labels": ["Label1", "Label2"]
}, callback); //issue

Get the pull requests for a repository (GET /repos/pksunkara/hub/pulls)

This query supports pagination.

ghrepo.prs(callback); //array of pull requests

Create a pull request (POST /repos/pksunkara/hub/pulls){
  "title": "Amazing new feature",
  "body": "Please pull this in!",
  "head": "octocat:new-feature",
  "base": "master"
}, callback); //pull request

Get the hooks for a repository (GET /repos/pksunkara/hub/hooks)

This query supports pagination.

ghrepo.hooks(callback); //array of hooks

Create a hook (POST /repos/pksunkara/hub/hooks)

  "name": "web",
  "active": true,
  "events": ["push", "pull_request"],
  "config": {
    "url": ""
}, callback); // hook

Get the README for a repository (GET /repos/pksunkara/hub/readme)

ghrepo.readme(callback); //file
ghrepo.readme('v0.1.0', callback); //file

Get the contents of a path in repository

ghrepo.contents('lib/index.js', callback); //path
ghrepo.contents('lib/index.js', 'v0.1.0', callback); //path

Create a file at a path in repository

ghrepo.createContents('lib/index.js', 'commit message', 'content', callback); //path
ghrepo.createContents('lib/index.js', 'commit message', 'content', 'v0.1.0', callback); //path

Update a file at a path in repository

ghrepo.updateContents('lib/index.js', 'commit message', 'content', 'put-sha-here', callback); //path
ghrepo.updateContents('lib/index.js', 'commit message', 'content', 'put-sha-here', 'v0.1.0', callback); //path

Delete a file at a path in repository

ghrepo.deleteContents('lib/index.js', 'commit message', 'put-sha-here', callback); //path
ghrepo.deleteContents('lib/index.js', 'commit message', 'put-sha-here', 'v0.1.0', callback); //path

Get archive link for a repository

ghrepo.archive('tarball', callback); //link to archive
ghrepo.archive('zipball', 'v0.1.0', callback); //link to archive

Get the blob for a repository (GET /repos/pksunkara/hub/git/blobs/SHA)

ghrepo.blob('18293abcd72', callback); //blob

Get users who starred a repository (GET /repos/pksunkara/hub/stargazers)

ghrepo.stargazers(1, 100, callback); //array of users
ghrepo.stargazers(10, callback);     //array of users
ghrepo.stargazers(callback);         //array of users

Get the teams for a repository (GET /repos/pksunkara/hub/teams)

ghrepo.teams(callback); //array of teams

Get a git tree (GET /repos/pksunkara/hub/git/trees/18293abcd72)

ghrepo.tree('18293abcd72', callback); //tree
ghrepo.tree('18293abcd72', true, callback); //recursive tree

Delete the repository (DELETE /repos/pksunkara/hub)


List statuses for a specific ref (GET /repos/pksunkara/hub/statuses/master)

ghrepo.statuses('master', callback); //array of statuses

Create status (POST /repos/pksunkara/hub/statuses/SHA)

ghrepo.status('18e129c213848c7f239b93fe5c67971a64f183ff', {
  "state": "success",
  "target_url": "",
  "description": "Build success."
}, callback); // created status

Github organizations api

Get information about an organization (GET /orgs/flatiron); //json

Update an organization (POST /orgs/flatiron)

  blog: ''
}, callback); // org

List organization repositories (GET /orgs/flatiron/repos)

This query supports pagination.

ghorg.repos(callback); //array of repos

Create an organization repository (POST /orgs/flatiron/repos)

  name: 'Hello-world',
  description: 'My first world program'
}, callback); //repo

Get an organization's teams (GET /orgs/flatiron/teams)

ghorg.teams(callback); //array of teams

Get an organization's members (GET /orgs/flatiron/members)

ghorg.members(callback); //array of github users

Check an organization member (GET /orgs/flatiron/members/pksunkara)

ghorg.member('pksunkara', callback); //boolean

Github issues api

Get a single issue (GET /repos/pksunkara/hub/issues/37); //issue

Edit an issue for a repository (PATCH /repos/pksunkara/hub/issues/37)

  "title": "Found a bug and I am serious",
}, callback); //issue

List comments on an issue (GET /repos/pksunkara/hub/issues/37/comments)

This query supports pagination.

ghissue.comments(callback); //array of comments

Github pull requests api

Get a single pull request (GET /repos/pksunkara/hub/pulls/37); //pull request

Update a pull request (PATCH /repos/pksunkara/hub/pulls/37)

  'title': 'Wow this pr'
}, callback); //pull request

Close a pull request

ghpr.close(callback); //pull request

Get if a pull request has been merged (GET /repos/pksunkara/hub/pulls/37/merge)

ghpr.merged(callback); //boolean

List commits on a pull request (GET /repos/pksunkara/hub/pulls/37/commits)

ghpr.commits(callback); //array of commits

List comments on a pull request (GET /repos/pksunkara/hub/pulls/37/comments)

ghpr.comments(callback); //array of comments

List files in pull request (GET /repos/pksunkara/hub/pulls/37/files)

ghpr.files(callback); //array of files

Github gists api

List authenticated user's gists (GET /gists)

This query supports pagination.

ghgist.list(callback); //array of gists

List authenticated user's public gists (GET /gists/public)

This query supports pagination.

ghgist.public(callback); //array of gists

List authenticated user's starred gists (GET /gists/starred)

This query supports pagination.

ghgist.starred(callback); //array of gists

List a user's public gists (GET /users/pksunkara/gists)

This query supports pagination.

ghgist.user('pksunkara', callback); //array of gists

Get a single gist (GET /gists/37)

ghgist.get(37, callback); //gist

Create a gist (POST /gists)

  description: "the description",
  files: { ... }
}), callback); //gist

Edit a gist (PATCH /gists/37)

ghgist.edit(37, {
  description: "hello gist"
}, callback); //gist

Delete a gist (DELETE /gists/37)


Fork a gist (POST /gists/37/forks)

ghgist.fork(37, callback); //gist

Star a gist (PUT /gists/37/star);

Unstar a gist (DELETE /gists/37/unstar)


Check if a gist is starred (GET /gists/37/star)

ghgist.check(37); //boolean

List comments on a gist (GET /gists/37/comments)

ghgist.comments(37, callback); //array of comments

Create a comment (POST /gists/37/comments)

ghgist.comments(37, {
  body: "Just commenting"
}, callback); //comment

Get a single comment (GET /gists/comments/1)

ghgist.comment(1, callback); //comment

Edit a comment (POST /gists/comments/1)

ghgist.comment(1, {
  body: "lol at commenting"
}, callback); //comment

Delete a comment (DELETE /gists/comments/1)


Github teams api

Get a team (GET /team/37); //json

Get the team members (GET /team/37/members)

ghteam.members(callback); //array of github users

Check if a user is part of the team (GET /team/37/members/pksunkara)

ghteam.member('pksunkara'); //boolean

Github search api

Search issues

  q: 'windows+state:open+repo:pksunkara/hub',
  sort: 'created'
  order: 'asc'
}, callback); //array of search results

Search repositories

  q: 'hub+language:go',
  sort: 'created',
  order: 'asc'
}, callback); //array of search results

Search users

  q: 'tom+followers:>100',
  sort: 'created',
  order: 'asc'
}, callback); //array of search results

Search code

  q: 'auth+in:file+repo:pksunkara/hub',
  sort: 'created',
  order: 'asc'
}, callback); //array of search results


npm test

If you like this project, please watch this and follow me.


Here is a list of Contributors


The following method names use underscore as an example. The library contains camel cased method names.

// public repos for unauthenticated, private and public for authenticated
me.is_watching('repo', callback);
me.start_watching('repo', callback);
me.stop_watching('repo', callback);
me.get_issues(params, callback);

// organization data
var org = octonode.Organization('bulletjs');

org.update(dict_with_update_properties, callback);
org.add_member('user', 'team', callback);
org.remove_member('user', callback);
org.is_public_member('user', callback);
org.make_member_public('user', callback);
org.conceal_member('user', callback);

org.get_team('team', callback);
org.create_team({name:'', repo_names:'', permission:''}, callback);
org.edit_team({name:'', permission:''}, callback);
org.delete_team('name', callback);
org.get_team_members('team', callback);
org.get_team_member('team', 'user', callback);
org.remove_member_from_team('user', 'team', callback);
org.create_repository({name: ''}, callback);
org.get_team_repositories('team', callback);
org.get_team_repository('team', 'name', callback);
org.add_team_repository('team', 'name', callback);
org.remove_team_repository('team', 'name', callback);

var repo = octonode.Repository('pksunkara/octonode');

repo.update({name: ''}, callback);

// collaborator information
repo.add_collaborator('name', callback);
repo.remove_collaborator('name', callback);

// commit data
repo.get_commit('sha-id', callback);
repo.get_commit_comments('SHA ID', callback);
repo.comment_on_commit({body: '', commit_id: '', line: '', path: '', position: ''}, callback);
repo.get_single_comment('comment id', callback);
repo.edit_single_comment('comment id', callback);
repo.delete_single_comment('comment id', callback);

// downloads
repo.create_download({name: ''}, 'filepath', callback);

// keys
repo.get_deploy_key('id', callback);
repo.create_deploy_key({title: '', key: ''}, callback);
repo.edit_deploy_key({title: '', key: ''}, callback);
repo.delete_deploy_key('id', callback);

// watcher data

// pull requests
repo.get_pull_request_comment('id', callback);
repo.create_pull_request_comment('id', {body:'', commit_id:'', path:'', position:''}, callback);
repo.reply_to_pull_request_comment('id', 'body', callback);
repo.edit_pull_request_comment('id', 'body', callback);
repo.delete_pull_request_comment('id', callback);
repo.get_issues(params, callback);
repo.get_issue('id', callback);
repo.create_issue({title: ''}, callback);
repo.edit_issue({title: ''}, callback);
repo.get_issue_comments('issue', callback);
repo.get_issue_comment('id', callback);
repo.create_issue_comment('id', 'comment', callback);
repo.edit_issue_comment('id', 'comment', callback);
repo.delete_issue_comment('id', callback);
repo.get_issue_events('id', callback);
repo.get_event('id', callback);
repo.get_label('id', callback);
repo.create_label('name', 'color', callback);
repo.edit_label('name', 'color', callback);
repo.delete_label('id', callback);
repo.get_issue_labels('issue', callback);
repo.add_labels_to_issue('issue', ['label1', 'label2'], callback);
repo.remove_label_from_issue('issue', 'labelid', callback);
repo.set_labels_for_issue('issue', ['label1', 'label2'], callback);
repo.remove_all_labels_from_issue('issue', callback);
repo.get_labels_for_milestone_issues('milestone', callback);
repo.get_milestone('id', callback);
repo.create_milestone('title', callback);
repo.edit_milestone('title', callback);
repo.delete_milestone('id', callback);

// raw git access
repo.create_blob('content', 'encoding', callback);
repo.get_commit('sha-id', callback);
repo.create_commit('message', 'tree', [parents], callback);
repo.get_reference('ref', callback);
repo.create_reference('ref', 'sha', callback);
repo.update_reference('ref', 'sha', force, callback);

I accept pull requests and guarantee a reply back within a day



Bug Reports

Report here. Guaranteed reply within a day.


Pavan Kumar Sunkara (

Follow me on github, twitter

Something went wrong with that request. Please try again.