Triggering GitHub Actions Workflow via Postman: A Step-by-Step Guide

Nitin Pathak
2 min readNov 10, 2023

--

Description: In this guide, we’ll walk you through the process of manually triggering a GitHub Actions workflow using Postman, a popular API testing tool. GitHub Actions is a powerful automation platform that allows you to automate your software development workflows. By following this step-by-step guide, you’ll learn how to initiate GitHub Actions workflows at your convenience, enabling greater control and flexibility in your development process. Whether you’re a developer, tester, or workflow manager, mastering this technique can streamline your CI/CD pipelines and enhance your development workflow.

Step 1: Create a GitHub Action Workflow: First, create a GitHub Actions workflow in your GitHub repository. This workflow should define the automation tasks you want to trigger. You can create a new workflow by creating a YAML file in the .github/workflows/ directory of your repository

Here’s a basic example of a workflow file (trigger.yml) that you can create:

In this example, the workflow is set up to run when a workflow_dispatch event occurs, which allows you to manually trigger it.

Step 2: Commit and Push Workflow File

Commit the workflow file (trigger.yml) to your GitHub repository and push it. This will trigger the workflow to be set up in your repository.

Step 3: Trigger the Workflow Manually with curl

To manually trigger the GitHub Actions workflow using curl, you can use GitHub’s API. Here’s an example curl command:

curl -X POST -H “Accept: application/vnd.github.v3+json” \ -H “Authorization: token YOUR_PERSONAL_ACCESS_TOKEN” \ https://api.github.com/repos/yourusername/yourrepository/actions/workflows/trigger.yml/dispatches \ -d ‘{“ref”:”main”}’

Replace the following placeholders in the curl command:

  • YOUR_PERSONAL_ACCESS_TOKEN: Your GitHub Personal Access Token. Make sure it has the necessary permissions to trigger workflows in your repository.
  • yourusername: Your GitHub username
  • yourrepository: The name of your GitHub repository
  • trigger.yml: The name of the workflow file you created

Step 4: Execute the curl Command in Postman

  1. Open Postman: Launch the Postman application.
  2. Create a New Request: Click on the “New” button in the top-left corner of the Postman interface to create a new request
  3. Set Request Type to POST: In the request details, set the HTTP request type to POST.
  4. Enter the API Endpoint: https://api.github.com/repos/USERNAME/REPOSITORY/actions/workflows/WORKFLOW_FILE_NAME/dispatches

Replace the placeholders with your GitHub information:

  • USERNAME: Your GitHub username.
  • REPOSITORY: The name of your GitHub repository
  • WORKFLOW_FILE_NAME: The name of your workflow file.

5. Add Headers: In the request headers section, include the “Authorization” header with your Personal Access Token (PAT):

  • Header Name: Authorization
  • Header Value: token YOUR_PERSONAL_ACCESS_TOKEN

6. Add Request Body: The body should contain a JSON object with the “ref” and any “inputs” your workflow requires:

{ “ref”: “main”, “inputs”: { “custom_event_name”: “This workflow triggered manually” } }

7. Send the Request: Click the “Send” button to execute the request.

#github #postman #automation #Tech9 #Techhappily

--

--

No responses yet