cover image

How to trigger a Github action with an HTTP request

Nov 6 '20 / 1 min read

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

on:
  repository_dispatch:
  schedule:
    - cron: '5 12 * * 0'

jobs:
  build:
    runs-on: ubuntu-latest

2. Get yourself a personal access token to use the Github API

Make sure you add repo and workflow permissions

3. Create the HTTP request

POST https://api.github.com/repos/<username>/<repo>/dispatches
Authorization: Bearer <Your personal access token here>

{"event_type": "hello"}
cURL
curl --request POST \
  --url 'https://api.github.com/repos/<USERNAME>/<REPO>/dispatches' \
  --header 'authorization: Bearer <TOKEN>' \
  --data '{"event_type": "hello"}'

Sources