Skip to content
Latchkey

How to Send a repository_dispatch With the gh CLI

gh api posts a repository_dispatch using the CLI login, so no manual Authorization header is needed.

Use gh api with --method POST against the dispatches endpoint. The CLI supplies the token, and -f/--input set the event_type and client_payload.

Steps

  • Authenticate once with gh auth login (or set GH_TOKEN).
  • Call gh api with --method POST on the dispatches path.
  • Pass event_type and nested client_payload fields.

Send the dispatch

Terminal
gh api \
  --method POST \
  repos/OWNER/REPO/dispatches \
  -f event_type=deploy-request \
  -f 'client_payload[ref]=main'

From another workflow

.github/workflows/ci.yml
steps:
  - env:
      GH_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
    run: gh api --method POST repos/OWNER/REPO/dispatches -f event_type=deploy-request

Gotchas

  • The default GITHUB_TOKEN cannot dispatch across repos; use a scoped PAT or app token.
  • A successful dispatch returns 204 with no body, so do not parse a response.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →