Search code examples
github-actions

how do I trigger a workflow dispatch event with gh api with inputs


so right now I have:

gh api --method POST -H "Accept: application/vnd.github+json" /repos/${{ github.repository }}/actions/workflows/30721645/dispatches -F run_id=${{ github.run_id }}

my workflow_dispatch event takes run_id as input, but the problem is that I get invalid_key for this request, how do I properly pass in the run_id to gh api?


Solution

  • It is a bit more tricky as you have to pass a JSON to gh api and you also need to pass a ref.

    This should work:

    jq -n '{"ref":"main","inputs":{"run_id":"${{github.run_id}}"}}' | gh api -H "Accept: application/vnd.github+json" --method POST /repos/${{ github.repository }}/actions/workflows/30721645/dispatches --input -