How To Trigger A Github Action With An Http Request


1.Create a new action with repository_dispatch trigger

Make sure your action is set to trigger on repository_dispatch event. This is the same event used when triggering the action through the UI.
name: Node.js CI

name:  Demo action todo list.

on:
  repository_dispatch:
  #workflow_dispatch:
  #schedule:
  #  - cron: '5 6 * * *'

jobs:
  build:
    runs-on: ubuntu-latest
2.Get yourself a personal access token to use the Github API

You can create one here: https://github.com/settings/tokens

Make sure you add repo and workflow permissions

3.Create the HTTP request

https://docs.github.com/en/[email protected]/rest/reference/actions#create-a-workflow-dispatch-event

POST https://api.github.com/repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches
Authorization: Bearer <Your personal access token here>
{"ref": "<BRANCH | TAG>"}

cURL

curl --request POST \
  --url 'https://api.github.com/repos/octocat/hello-world/actions/workflows/42/dispatches' \
  -H "Accept: application/vnd.github.v3+json" \
  -H "authorization: Bearer <TOKEN>" \
  -d '{"ref":"release"}'
Ref

https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event

https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#repository_dispatch

https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token