BETA

Skip links

  • Skip to primary navigation
  • Skip to content
  • Skip to footer
Queensland government logo Queensland government logo
Sign in Sign out
Sign in
  • Profile summary
  • Sign out
Department of Education Department of Education Developer Portal
  • Home
  • Tags
  • Chat
  • New
    APIs
  • Help
  • Contact us
  • Dark mode
  • Home
  • Tags
  • Chat
  • New
    APIs
  • Help
  • Contact us
  • My profile
  • Dark mode

How to call GitHub APIs using the Octokit library?

Jeny Amatya Government
by Jeny Amatya
19 April 2023
Last updated 11 May 2023
Technology
Technology

To call the GitHub API using the Octokit library, you first need to install it in your project by running the following command in your terminal:

npm install @octokit/rest

Once you have installed Octokit, you can create a new instance of the Octokit REST client and use it to make API requests. Here’s an example of how to create a client and get information about a user:

const { Octokit } = require("@octokit/rest");
const octokit = new Octokit();

octokit.users.getByUsername({
 username: "octocat"
}).then(({ data }) => {
 console.log(data);
}).catch((error) => {
 console.error(error);
});

In this example, we create a new instance of the Octokit client, and then use the getByUsername method to get information about a user with the username “octocat”. The result of the API call is returned as a Promise, which we handle using the then and catch methods.

You can use other methods provided by Octokit to interact with other parts of the GitHub API, such as creating repositories, managing issues, and more. The Octokit documentation provides detailed information about all available methods and how to use them.

Powered by Link to AI chat
  • Copyright
  • Disclaimer
  • Privacy
  • Right to information
  • Accessibility
  • Jobs in Queensland Government
  • Other languages

© The State of Queensland (Department of Education) 2025

Queensland Government