Home > Back-end >  GitHub Actions: Must have admin rights to trigger workflow_dispatch?
GitHub Actions: Must have admin rights to trigger workflow_dispatch?

Time:08-18

Using the github API I am trying to manually start a workflow using:

  curl \
  -X POST \
  -H "Accept: application/vnd.github json" \ 
  -H "Authorization: MY_TOKEN" \
  https://api.github.com/repos/djpr-data/djprdashdata/actions/workflows/refresh-data.yaml/dispatches 

but I keep getting an authentication error:

{
  "message": "Must have admin rights to Repository.",
  "documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event"
}

This seems to be a similar issue to this question. But my PAT token has all admin and repo scopes selected. I also have my user account setup as admin for the repository and I have added a workflow dispatch to the workflow yaml file.

  workflow_dispatch:
    inputs:
      tags:
        description:
          "run from cmdline"

I have been following the docs at https://docs.github.com/en/rest/actions/workflows#create-a-workflow-dispatch-event and have had no problems using the API to retrieve all previous workflow jobs. I have also tried the runs and jobs endpoints but get the same error. So I am now not sure what else I can do. Is there somewhere else I need to set permissions?

Thanks

CodePudding user response:

This is a poor error message to tell you that your request is not formed correctly. If you want to pass a PAT as a header, you need to prefix it with token, as described in the docs:

-H "Authorization: token MY_TOKEN"

Once that's resolved, however, you'll also get an error because you don't pass the required ref payload. Assuming your default branch is main, here's a correct curl command:

> export MY_TOKEN=gha_abcdef
> curl \
  -X POST \
  -H "Accept: application/vnd.github json" \ 
  -H "Authorization: token $MY_TOKEN" \
  -d '{"ref": "main"}' \
  https://api.github.com/repos/djpr-data/djprdashdata/actions/workflows/refresh-data.yaml/dispatches
  • Related