Open In App

REST API Endpoints For GitHub Actions Variables

Last Updated : 28 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

GitHub Actions is used to automate workflows, build, test, and deploy code. To make workflows more dynamic and secure, GitHub Actions allows you to use variables, which can store data like configuration values, secrets, or other necessary information.

GitHub exposes a REST API to manage these variables efficiently, providing developers with full control over the setup, modification, and deletion of variables through API calls. In this article, we will explore more about REST API Endpoints For GitHub Actions Variables.

What are GitHub Actions Variables?

Variables in GitHub Actions allow you to store and reuse arbitrary data across workflows. They can be used to store anything from configuration settings to deployment keys, making your workflows more flexible and secure. There are two types of variables in GitHub Actions:

  1. Repository Variables: These variables are specific to a particular repository and can be accessed only within that repository's workflows.
  2. Organization Variables: These variables are shared across all repositories within an organization and can be accessed by workflows in any repository under that organization.

Overview of REST API Endpoints for GitHub Actions Variables

GitHub provides REST API endpoints to manage both repository and organization-level variables. These endpoints allow you to:

  • List existing variables
  • Create new variables
  • Retrieve details of a specific variable
  • Update existing variables
  • Delete variables

This flexibility ensures that you can programmatically manage your workflow variables, automate processes, and maintain consistency across different repositories or environments.

Common Use Cases for GitHub Actions Variables API

The REST API for GitHub Actions variables can be used in various cases, such as:

  • Automating CI/CD Pipelines: Dynamically update variables like deployment environments or build configurations.
  • Centralized Management: Manage variables at the organization level to enforce consistency across multiple repositories.
  • Security and Compliance: Programmatically create and manage sensitive data without exposing it in the source code.
  • Simplified Maintenance: Easily update or delete variables without manually navigating through the GitHub UI.

List of REST API Endpoints for GitHub Actions Variables

1. List Repository Variables

  • Endpoint: GET /repos/{owner}/{repo}/actions/variables
  • Description: Retrieves a list of all variables defined in a specific repository.
  • Example:
    curl -H "Authorization: token YOUR_GITHUB_TOKEN" \
    https://api.github.com/repos/owner/repo/actions/variables

2. Get a Repository Variable

  • Endpoint: GET /repos/{owner}/{repo}/actions/variables/{name}
  • Description: Fetches a specific variable from a repository by its name.
  • Example:
    curl -H "Authorization: token YOUR_GITHUB_TOKEN" \
    https://api.github.com/repos/owner/repo/actions/variables/VAR_NAME

3. Create a Repository Variable

  • Endpoint: POST /repos/{owner}/{repo}/actions/variables
  • Description: Creates a new variable in the specified repository.
  • Request Body:
    {
    "name": "VAR_NAME",
    "value": "variable_value"
    }
  • Example:
    curl -X POST -H "Authorization: token YOUR_GITHUB_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"name": "NEW_VAR", "value": "new_value"}' \
    https://api.github.com/repos/owner/repo/actions/variables

4. Update a Repository Variable

  • Endpoint: PATCH /repos/{owner}/{repo}/actions/variables/{name}
  • Description: Updates an existing variable in the repository.
  • Request Body:
    {
    "value": "updated_value"
    }
  • Example:
    curl -X PATCH -H "Authorization: token YOUR_GITHUB_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"value": "updated_value"}' \
    https://api.github.com/repos/owner/repo/actions/variables/VAR_NAME

5. Delete a Repository Variable

  • Endpoint: DELETE /repos/{owner}/{repo}/actions/variables/{name}
  • Description: Deletes a specific variable from the repository.
  • Example:
    curl -X DELETE -H "Authorization: token YOUR_GITHUB_TOKEN" \
    https://api.github.com/repos/owner/repo/actions/variables/VAR_NAME

6. List Organization Variables

  • Endpoint: GET /orgs/{org}/actions/variables
  • Description: Retrieves all variables defined at the organization level.
  • Example:
    curl -H "Authorization: token YOUR_GITHUB_TOKEN" \
    https://api.github.com/orgs/org/actions/variables

7. Get an Organization Variable

  • Endpoint: GET /orgs/{org}/actions/variables/{name}
  • Description: Fetches a specific variable from an organization by its name.
  • Example:
    curl -H "Authorization: token YOUR_GITHUB_TOKEN" \
    https://api.github.com/orgs/org/actions/variables/VAR_NAME

8. Create an Organization Variable

  • Endpoint: POST /orgs/{org}/actions/variables
  • Description: Creates a new variable for the organization.
  • Request Body:
    {
    "name": "VAR_NAME",
    "value": "variable_value"
    }
  • Example:
    curl -X POST -H "Authorization: token YOUR_GITHUB_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"name": "ORG_VAR", "value": "org_value"}' \
    https://api.github.com/orgs/org/actions/variables

9. Update an Organization Variable

  • Endpoint: PATCH /orgs/{org}/actions/variables/{name}
  • Description: Updates an existing variable at the organization level.
  • Request Body:
    {
    "value": "updated_value"
    }
  • Example:
    curl -X PATCH -H "Authorization: token YOUR_GITHUB_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"value": "updated_value"}' \
    https://api.github.com/orgs/org/actions/variables/VAR_NAME

10. Delete an Organization Variable

  • Endpoint: DELETE /orgs/{org}/actions/variables/{name}
  • Description: Deletes a specific variable from the organization.
  • Example:
    curl -X DELETE -H "Authorization: token YOUR_GITHUB_TOKEN" \
    https://api.github.com/orgs/org/actions/variables/VAR_NAME

Authentication and Permissions for GitHub Actions Variables API

To use these REST API endpoints, you need an access token with the appropriate permissions:

  • Repository Variables: Requires repo or workflow scope for personal access tokens (PAT).
  • Organization Variables: Requires admin:org or workflow scope for PAT.

Ensure that your access token has the necessary permissions to manage the variables for the respective repository or organization.

Example Use Cases and Code Snippets

Example 1: Automating Variable Creation for Multiple Repositories

Suppose you have multiple repositories and want to automate the creation of a common variable for all of them:

REPOS=("repo1" "repo2" "repo3")
for REPO in "${REPOS[@]}"
do
curl -X POST -H "Authorization: token YOUR_GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "COMMON_VAR", "value": "common_value"}' \
https://api.github.com/repos/owner/$REPO/actions/variables
done

Example 2: Updating Organization-Level Variables Based on Environment

You can use the API to dynamically update variables based on the environment:

ENVIRONMENT="staging"
if [ "$ENVIRONMENT" == "staging" ]; then
curl -X PATCH -H "Authorization: token YOUR_GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d '{"value": "staging_value"}' \
https://api.github.com/orgs/org/actions/variables/ORG_VAR
fi

Troubleshooting Common Issues with GitHub Actions Variables API

  • Permission Denied: Ensure your token has the required scope (repo, workflow, admin:org).
  • Variable Name Conflicts: Verify that the variable name is unique within the context (repository or organization).
  • Rate Limiting: GitHub APIs have rate limits. Make sure you are within the limit or use caching strategies.

Similar Reads

REST API Endpoints For Git Tags
In Git, tags are used to mark specific commits as important, typically signifying a release. Unlike branches, tags are immutable references, making them perfect for marking stable points in your repository’s history, such as version releases. Why Use REST API for Git Tags?Interacting with Git tags via REST APIs allows for easy integration with CI/C
3 min read
Consuming a REST API ( Github Users ) using Fetch - React Client
In this article, you will learn to develop a React application, which will fetch the data from a REST API using Fetch. We will use GitHub Users API to fetch the user's public information with their username. You can find the API reference and source code links at the end of this article. Prerequisites:NodeJS or NPMReactJSSteps to Create the React A
3 min read
GitHub REST API
The GitHub REST API allows developers to interact with GitHub programmatically, enabling you to manage repositories, handle issues, automate workflows, and integrate GitHub with other tools and platforms. Whether you're building an application, automating repetitive tasks, or just curious about how GitHub works behind the scenes, the REST API is a
4 min read
Getting Started With GitHub REST API
The GitHub REST API is a powerful tool that allows developers to interact with a list of features of GitHub. Whether you're automating tasks, building integrations, or simply managing your GitHub resources more efficiently, the REST API provides a versatile and accessible entry point. In this article, we will walk you through everything you need to
5 min read
Flutter - Building and Releasing APK using GitHub Actions
Github Actions is a Github tool that allows users to create CI/CD pipelines directly in a Github project instead of going to a third-party website. It assists us in developing, testing, and releasing our project very conveniently. In this article, we're going to build a workflow for our flutter project. We'll first build the project using the workf
3 min read
Introduction to GitHub Actions
GitHub Actions is a CI/CD (Continuous Integration/ Continuous Deployment) platform for automating the builds, test, and deployment process. Using GitHub actions, we can build and test every pull request in the repository using workflows, or push the merged pull requests to production with workflows. GitHub Actions allows you to conduct processes in
4 min read
How to Upload Android APK to Testers Group in Firebase Using GitHub Actions?
Testing is always required whenever we build an app to ensure it functions properly in production. It might be time-consuming and inconvenient to send the application to the testers every time new code is merged into the codebase. So to solve this problem, CD pipelines can be used to deliver the software to the testers. In this article, we'll be le
3 min read
How to Publish Docker Image to Dockerhub Using Github Actions?
Pre-requisites: GitHub Actions, Docker Hub Publishing Docker images to Docker Hub using GitHub Actions is a simple and efficient process that can automate your image-building and publishing process. What are Github Actions?GitHub Actions is a CI/CD (Continuous Integration/Continuous Deployment) platform integrated with GitHub. It enables developers
3 min read
Spring Boot - Continuous Integration Using GitHub Actions
Let's say we have two or more developers who are merging code into a single repository. There can be issues in merging code from different developers. So the Continuous Integration tools help in solving not just that but many other things like: Run an automated build after successful merging (like build, test code coverage, etc.).We can also automa
3 min read
Basic CI Workflow For Android using GitHub Actions
Continuous integration (CI) is a software development process in which the team members can integrate their work. For Android developers, setting up a CI pipeline can greatly enhance productivity and code quality. GitHub Actions, a powerful automation tool integrated into GitHub, provides an excellent platform for creating a CI workflow for Android
2 min read
Automated Release for Android Using GitHub Actions
Automating the release process for Android applications can significantly enhance efficiency, reduce manual errors, and ensure consistent delivery. GitHub Actions provides a powerful platform to automate workflows directly from your GitHub repository. This article will guide you through setting up an automated release pipeline for Android using Git
3 min read
How to Set Up a CI Pipeline for Ktor Using GitHub Actions?
In this article, we'll look at how to use GitHub Actions to create a robust and effective Continuous Integration (CI) pipeline for Ktor applications. Developers have a great foundation to construct high-performance server-side apps thanks to Ktor, a versatile and lightweight Kotlin framework for building web applications. We can automate the build,
6 min read
How To Set Up Merge Queues in GitHub Actions?
Managing multiple pull requests (PRs) efficiently is important in a collaborative development environment. Merge queues help automate and control the merging of PRs in sequential order, ensuring that only PRs that pass all checks are merged into the main branch. In this article, we will discuss how to set up merge queues using GitHub Actions. Table
4 min read
The Matrix Strategy in GitHub Actions
GitHub Actions provides a platform for automating your CI/CD pipelines, allowing you to run workflows directly from your GitHub repositories. One of the most powerful features of GitHub Actions is the matrix strategy, which allows to run a single job in multiple configurations. This can include different operating systems, language versions, enviro
5 min read
GitHub Actions
GitHub Actions is a powerful CI/CD (Continuous Integration/Continuous Deployment) tool integrated directly into GitHub. It allows developers to automate, customize, and execute workflows in their repositories. With GitHub Actions, you can automate software development processes, from testing and building to deployment and monitoring. In this articl
5 min read
How to test API Endpoints with Postman and Express ?
Postman, a popular API development and testing tool allowing developers to interact with APIs. In this guide, we'll explore the basics of testing API endpoints using Postman and Express, providing clear steps and examples. Prerequisites:Basics of Express JS and Node JS.Postman should be installed.Steps to test API endpoints with Postman & Expre
2 min read
Difference Between REST API and RPC API
REST and RPC are design architectures widely used in web development to build APIs (Application Programming Interface). It is a set of instructions that permits two systems to share resources and services. The client creates a request to the server that responds to it with data in JSON or XML format. REST APIs It stands for Representational State T
3 min read
Know the Difference Between REST API and RESTful API
APIs (Application Programming Interface) act as an interface between two applications to interact and provide the relevant data. It uses a set of protocols using which the operation is done. Salesforce was the first organization to officially launch API, followed by eBay and Amazon. Also, 60% of transactions made on eBay use their APIs. If we talk
5 min read
Difference between REST API and SOAP API
REST (Representational State Transfer) and SOAP (Simple Object Access Protocol) are the most common methods for communications These services enable web to communicate with the servers with HTTP protocol. REST is architectural style that works over HTTP for communication while SOAP is a protocol with strict standards and is helpful for complex syst
2 min read
How to Upload a Project through GitHub Desktop on GitHub
GitHub Desktop is a user-friendly application that simplifies the process of managing your GitHub repositories on your local machine. If you’re looking to upload a project to GitHub using GitHub Desktop, this guide will walk you through the steps, making the process straightforward and accessible even for beginners. What is GitHub Desktop?GitHub De
3 min read
Node.js Building simple REST API in express
Let's have a brief introduction about the Express framework before starting the code section:Express: It is an open-source NodeJs web application framework designed to develop websites, web applications, and APIs in a pretty easier way. Express helps us to handle different HTTP requests at specific routes.As it is NodeJs web framework so make sure
2 min read
How to create a REST API using Java Spring Boot
Representational state transfer (REST) is a software architectural style that defines a set of constraints to be used for creating Web services. Web services that conform to the REST architectural style, called RESTful Web services, provide interoperability between computer systems on the Internet. RESTful Web services allow the requesting systems
6 min read
REST API in Hyperledger
REST, or Representational State Transfer, is an architectural style for building web services. It is based on a set of principles that define how web resources should be defined, accessed, and manipulated. One of the key principles of REST is the use of the HTTP protocol for communication between clients and servers. This means that REST APIs are b
7 min read
How to create Covid19 Country wise status project using REST API ?
Today, All Countries in the world fighting with Coronavirus. Every day, Coronavirus cases rising rapidly. It is important for all to keep track of COVID Cases daily and should try to keep himself/herself safe. We have made small web apps that will tell you the total no of cases, new cases, new death, recovery, etc. to the user. You have to just ent
7 min read
Best Coding Practices For Rest API Design
JSON, Endpoints, Postman, CRUD, Curl, HTTP, Status Code, Request, Response, Authentication, All these words are familiar to you if you are in backend development and you have worked on API (Application Programming Interface). Being a developer you might have worked on some kind of APIs (especially those who are experienced developers). Maybe a paym
10 min read
Why REST API is Important to Learn?
API... Being a developer what comes to your mind first when you listen to this word... JSON, Endpoints, Postman, CRUD, Curl, HTTP, Status Code, Request, Response, Authentication, or something else... If you're familiar with the above word then surely you might have worked on some kinds of APIs (especially those who are experienced developers) in yo
8 min read
Consuming a Rest API with Axios in Vue.js
Many times when building an application for the web that you may want to consume and display data from an API in VueJS using JavaScript fetch API, Vue resource, jquery ajax API, but a very popular and most recommended approach is to use Axios, a promise-based HTTP client. Axios is a great HTTP client library. Similar to JavaScript fetch API, it use
2 min read
Build a Social Media REST API Using Node.js: A Complete Guide
Developers build an API(Application Programming Interface) that allows other systems to interact with their Application’s functionalities and data. In simple words, API is a set of protocols, rules, and tools that allow different software applications to access allowed functionalities, and data and interact with each other.API is a service created
15+ min read
How to generate document with Node.js or Express.js REST API?
Generating documents with Node and Express REST API is an important feature in the application development which is helpful in many use cases. In this article, we will discuss two approaches to generating documents with Node.js or Express.js REST API. Table of Content Document Generation using PdfKit libraryDocument Generation using Puppeteer libra
3 min read
How to Create A REST API With JSON Server ?
Setting up a RESTful API using JSON Server, a lightweight and easy-to-use tool for quickly prototyping and mocking APIs. JSON Server allows you to create a fully functional REST API with CRUD operations (Create, Read, Update, Delete) using a simple JSON file as a data source. Table of Content GET Request Returns a List of all UsersPOST Request to c
4 min read
Article Tags :
three90RightbarBannerImg