The GitHub REST API allows users to create workflow dispatch events programmatically. For example, the test.yaml workflow in this repo can be dispatched with
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
https://api.github.com/repos/vlukashov/boolean-workflow-input-issue/actions/workflows/test.yaml/dispatches \
-d '{"ref":"main"}'The test.yaml workflow has an optional string input name:
inputs:
name:
description: An optional string workflow input
type: stringThe /dispatches REST API works regardless of whether or not the name input is provided.
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
https://api.github.com/repos/vlukashov/boolean-workflow-input-issue/actions/workflows/test.yaml/dispatches \
-d '{"ref":"main","inputs":{"name":"Mona the Octocat"}}'The with-boolean-input branch of this repo adds an optional boolean input to the test.yaml workflow:
has_admin_role:
description: An optional boolean workflow input
type: booleanWith that, the API calls that used to work now fail:
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
https://api.github.com/repos/vlukashov/boolean-workflow-input-issue/actions/workflows/test.yaml/dispatches \
-d '{"ref":"with-boolean-input","inputs":{"name":"Mona the Octocat"}}'
{
"message": "Provided value '' for input 'has_admin_role' not in the list of allowed values",
"documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event"
}The API call fails in the same way regardless whether or not it includes the inputs parameter at all.
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
https://api.github.com/repos/vlukashov/boolean-workflow-input-issue/actions/workflows/test.yaml/dispatches \
-d '{"ref":"with-boolean-input"}'
{
"message": "Provided value '' for input 'has_admin_role' not in the list of allowed values",
"documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event"
}Adding any optional workflow inputs should not cause working API calls to fail.
Do not use the boolean input type.
Instead, use the choice type with true and false options, and false as the default value.