Reputation: 7397
I want to trigger a GitHub Actions workflow manually. Through the docs I found out I can do so through a repository dispatch event.
The problem is that when I hit the API at the /dispatches
endpoint, I get the following error:
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/repos/#create-a-repository-dispatch-event"
}
I have write access to the repo. I generated myself an access token.
Is the dispatches functionality enabled by default or do I need to "enable" it somehow, so the the /dispatches
endpoint becomes available? Either I didn't look well enough, or this is not described in the docs.
I don't know if it makes a difference, but the repo is owned by an organization, not by an individual user.
Upvotes: 9
Views: 7635
Reputation: 1
François Roland mentioned:
the doc says "you can replace workflow_id by the name of the file". But that didn't work.
You can use the name of the file if you use its full URL-encoded path relative to the repo's root. For example I have a workflow in a repo of mine at .github/workflows/maven.yml
, so my trigger URI looks like https://api.github.com/repos/${{ github.repository_owner }}/other_repo_name/actions/workflows/.github%2Fworkflows%2Fmaven.yml/dispatches
.
I also found it helpful to list all of the workflows in the target repo to see their paths. This also helps to confirm that the token I'm using has got the necessary privileges to be able to see them. If it doesn't then it'll return with a 404.
I have a workflow on one repo triggering a workflow on a different repo that has the same owner. The target repo needs to have a workflow_dispatch
trigger to allow it to be triggered like this, else you get a 422 response to the above dispatch request (assuming that your token has permission to see the other repo in the first place):
on:
workflow_dispatch:
Upvotes: 0
Reputation: 1
I had the same error - followed the doc to the letter all the headers were set, token had correct privileges... but still had a 404
the doc says "you can replace workflow_id by the name of the file". But that didn't work.
I ended doing a post request to {{baseUrl}}/repos/{{owner}}/{{repo}}/actions/workflows
and grabbed the id from there.
from that point, the call to {{baseUrl}}/repos/{{owner}}/{{repo}}/actions/workflows/{{workflowId}}/dispatches
worked
Upvotes: 0
Reputation: 7397
The problem turned out to be very basic. I was sending the Authorization
header with Bearer
prefix, before the actual token, whereas I was supposed to send it with token
prefix.
Needless to say, the returned error message is quite misleading.
Upvotes: 11