GitHub API Access

Working with GitHub APIs is a powerful tool in GitHub Actions. There are a variety of methods of accessing GitHub's APIs depending on the language you wish to use.


In all workflows, there is a default secret called GITHUB_TOKEN which provides a personal access token Read/Write access to many APIs on the specific repo.

It can be inserted anywhere in a workflow in the env key at the workflow, job, or step level. For example at the job level:

# now able to use GITHUB_TOKEN

Note: If you need API access outside the current repo, you'll need to create a personal access token

Javascript: @actions/github

As part of the Actions Toolkit, a wrapper around the JS Octokit client is available.

To use it, download the @actions/github node module.

yarn add @actions/github

Then for instance, imagine you are running a workflow on a new issue, you could create a comment on it.

const github = require("@actions/github")
// Access token provided by GitHub in all actions
const token = process.env.GITHUB_TOKEN
// GitHub event payload
const context = github.context
// Create a
const octokit = new github.GitHub(token)
// Example: create a comment on an issue
body: "Thanks for submitting an issue! We will get to it shortly",

Other Languages: Octokit

Alongside such, the Octokit org has plenty of other clients for other languages and methods.

As well as other third party companies have libraries as well

Edit this page on GitHub