Trigger GitHub Actions via API | Generated by AI

Home 2026.02

Question: How to trigger a GitHub Actions workflow by API?

Answer:

There are two main ways to trigger a GitHub Actions workflow via the GitHub REST API:

  1. Using workflow_dispatch — Recommended for manually triggering a specific workflow (most common use case).
    The workflow must include on: workflow_dispatch: (optionally with inputs).

  2. Using repository_dispatch — For triggering workflows from external systems with a custom event type (useful for cross-repo or third-party integrations).

1. Trigger via workflow_dispatch (preferred method)

Workflow file requirement (.github/workflows/my-workflow.yml):

on:
  workflow_dispatch:
    inputs:
      environment:
        description: 'Environment to deploy to'
        required: true
        default: 'staging'
      version:
        description: 'Version tag'
        required: false

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Deploying to $ version $"

API Endpoint
POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches

Example using curl (2022-11-28 API version — current as of 2026):

curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer YOUR_PERSONAL_ACCESS_TOKEN" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/OWNER/REPO/actions/workflows/deploy.yml/dispatches \
  -d '{
    "ref": "main",
    "inputs": {
      "environment": "production",
      "version": "v1.5.0"
    }
  }'

Using GitHub CLI (simpler):

gh workflow run deploy.yml \
  --ref main \
  -f environment=production \
  -f version=v1.5.0

2. Trigger via repository_dispatch (custom events)

Workflow file requirement:

on:
  repository_dispatch:
    types: [deploy, build, test]

API Endpoint
POST /repos/{owner}/{repo}/dispatches

Example curl:

curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer YOUR_PERSONAL_ACCESS_TOKEN" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/OWNER/REPO/dispatches \
  -d '{
    "event_type": "deploy",
    "client_payload": {
      "environment": "prod",
      "service": "api"
    }
  }'

In the workflow you can access:
github.event.client_payload.environment

Authentication & Permissions

Quick Tips

References:


Back Donate