Sub topic 12
Starting manual runs from the UI, CLI and API
This chapter assumes you can read workflow YAML and have already added a workflow_dispatch trigger with typed inputs. Here you start that workflow in three ways: the Actions tab, the GitHub CLI, and the REST API.
What must be true first
A manual run only works when the workflow file defines workflow_dispatch and exists on the repository's default branch. The "Run workflow" button and the gh and API calls all rely on that. You can choose another branch or tag to run against, but GitHub finds the workflow definition through the default branch.
Here is the workflow used in the examples below.
name: Deploy
on:
workflow_dispatch:
inputs:
environment:
description: Target environment
type: choice
options: [staging, production]
default: staging
dry_run:
description: Skip the real deployment
type: boolean
default: true
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Show chosen options
env:
TARGET: ${{ inputs.environment }}
DRY_RUN: ${{ inputs.dry_run }}
run: echo "Deploying to $TARGET (dry run: $DRY_RUN)"Starting a run from the UI
- Open the repository and select the Actions tab.
- Choose Deploy in the left sidebar.
- Select Run workflow. A form appears.
- Pick the branch or tag, fill in the inputs, and select Run workflow again.
The form is generated from your inputs block. Choice inputs become drop-downs and boolean inputs become checkboxes.
Starting a run from the GitHub CLI
The gh workflow run command sends the same request. Use --ref to pick the branch and -f to pass each input as a name=value pair.
gh workflow run deploy.yml --ref main -f environment=staging -f dry_run=falseYou can name the workflow by file name, display name, or numeric ID. To follow the result, list recent runs and watch one.
gh run list --workflow deploy.yml --limit 3
gh run watchStarting a run from the REST API
The API endpoint is POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches. The body needs ref and may include inputs. Success returns 204 No Content with no body, so the response does not contain a run ID.
curl -L -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/actions/workflows/deploy.yml/dispatches \
-d '{"ref":"main","inputs":{"environment":"staging","dry_run":"false"}}'Replace OWNER and REPO with your values. The token needs write access to Actions. For a fine-grained token, that is the "Actions: write" permission.
Common errors
| Symptom | Likely cause |
|---|---|
| No "Run workflow" button | The workflow has no `workflow_dispatch`, or the file is not on the default branch |
| `HTTP 422` from `gh` or the API | An input name is wrong, a required input is missing, or the value is not one of the choice options |
| `HTTP 404` from the API | Wrong workflow name, or the token cannot see the repository |
| `HTTP 403` from the API | The token lacks Actions write permission |
Exercise
You call the dispatch API and receive 204 No Content, but you need the new run's ID. Why is it missing, and how can you find the run?
Show answer
The dispatch endpoint only confirms that the request was accepted, so it returns no body. List recent runs afterwards, for example with gh run list --workflow deploy.yml or the "list workflow runs" API with event=workflow_dispatch, and pick the newest one.