Reputation: 639
I create simple github action with workflow_dispatch.
name: Run Workflow Dispatch
on:
workflow_dispatch:
inputs:
version:
description: 'version'
required: true
default: 'latest'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- run: |
echo "version: ${{ github.event.inputs.version }}"
I create request by curl.
curl -X POST \
-H "Accept: application/vnd.github.everest-preview+json" \
-H "Authorization: token xxxxxxxxx" \
https://api.github.com/repos/patsevanton/workflow-dispatch-client-payload/actions/workflows/workflow_dispatch.yml/dispatches \
--data '{"event_type": "my-dispatch", "client_payload": {"ref": "main"}}'
But i get error:
{
"message": "Invalid request.\n\n\"client_payload\", \"event_type\" are not permitted keys.\n\"ref\" wasn't supplied.",
"documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event"
}
How create correct workflow_dispatch in github action? How create correct request to workflow_dispatch in github action?
Upvotes: 2
Views: 6242
Reputation: 23070
It seems you are confusing 2 workflows triggers event that are available on Github Actions.
The workflow_dispatch
and the repository_dispatch
event.
To trigger a workflow_dispatch
event remotely, you need to use the following endpoint:
https://api.github.com/repos/{owner}/{repository}/actions/workflows/{workflow_id}/dispatches
Here is the related documentation on Github
Note that you can use a body with this POST service, informing eventual inputs
.
To trigger a repository_dispatch
event remotely, you need to use the following endpoint:
https://api.github.com/repos/{owner}/{repository}/dispatches
Here is the related documentation on Github
In that case, you can use a client_payload
parameter as well as an event_type
parameter.
In your case, it seems you want to trigger a workflow dispatch event using a mixture of the workflow dispatch endpoint with the repository dispatch event client_payload
(that is not an available parameter on this endpoint).
Therefore, if you want to trigger the workflow, the first option would be using a repository dispatch event to trigger your workflow, updating the workflow trigger in your workflow file to use repository_dispatch
instead of the workflow_dispatch
and the endpoint you're calling with the curl command.
The other option is to call the other endpoint with your curl command (the one related to workflow dispatch
instead of the one related to repository dispatch
, informing the inputs
parameter instead of the client_payload
parameter.
Upvotes: 6