Invoke GitHub Actions workflow manually and pass parameters

Viewed 20525

I want to pass some dynamic parameters and invoke my GitHub Actions workflow manually (ideally via some API). Is this possible?

3 Answers

I think the correct answer to this is using a repository_dispatch NOT a workflow_dispatch.

Only repository dispatch allows you to trigger a workflow from an API call.

Docs

Hand Holding example

Summary:

  • URL Endpoint:
https://api.github.com/repos/{owner}/{repo}/dispatches
  • Example cURL call:
curl -X POST -H "Accept: application/vnd.github.v3+json" -H "authorization: Bearer <token>" https://api.github.com/repos/{owner}/{repo}/dispatches -d '{"event_type": "type1","client_payload": {"key1": "Hello from CRUD"}}'

To trigger a workflow_dispatch via API, the documentation can be found at https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-a-workflow-dispatch-event

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

where {workflow_id} can also be the filename of the workflow (which makes things a lot easier).

An example curl from the documentation:

curl \
  -X POST \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/octocat/hello-world/actions/workflows/42/dispatches \
  -d '{"ref":"ref"}'
Related