52

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

3 Answers 3

65

With the workflow_dispatch event trigger, you can do the manual triggers easily.

Flow:

on: 
  workflow_dispatch:
    inputs:
      logLevel:
        description: 'Log level'     
        required: true
        default: 'warning'
      tags:
        description: 'Test scenario tags'  

Manual trigger screenshot: screenshot

Blog post announcement reference, https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/

5
22

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"}}'
2
  • 3
    Wish I could upvote more than once. This is the only answer which specified that I can send "inputs" by sending "client_payload". Even the docs don't say that. Docs I'm referring to: docs.github.com/en/rest/reference/… Thank you Commented Mar 3, 2021 at 22:20
  • Doesn't the answer below show how workflow_dispatch can be triggered from the API? Commented Mar 24, 2023 at 15:40
6

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"}'
2
  • 1
    Also possible via gh CLI: gh workflow run workflow-name.yml -f param1=value1 -f param2=value2
    – jakub.g
    Commented May 5, 2023 at 9:17
  • 2
    Is there a way to create a clickable hyperlink that will dispatch a workflow? Meaning is there a way to do it from a GET without a body? Commented Jun 19, 2023 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.