API workflow_dispatch not running in workflow

Hi :+1:
I’m using the GitHub actions API to run a workflow on a repository:

url = "{0}/repos/{1}/actions/workflows/{2}/dispatches".format(
                self.api_url, self.repository_path, workflow_id
            )
            headers = {
                "Authorization": "token %s" % self.token,
                "Accept": "application/vnd.github.v3+json",
            }
            data = {"ref": ref}

            response = requests.post(url, headers=headers, data=json.dumps(data))

When I run the request in the local environment, it works and I can see the flow running in the ACTIONS tab of the repository. When I run the same script in a job with GitHub Actions, the output is the same but the workflow doesn’t run (No errors - code 204)

Any ideas? :confused:

PS: I’m using the same configuration in both tests (Local env and GitHub)

The default token available to a GitHub Action (GITHUB_TOKEN) cannot trigger other Actions.

When you use the repository’s GITHUB_TOKEN to perform tasks on behalf of the GitHub Actions app, events triggered by the GITHUB_TOKEN will not create a new workflow run
Using the GITHUB_TOKEN in a workflow

The reason this works locally is that you’re authenticated as yourself, so for this to work inside a GitHub Action you’ll need to use a Personal Access Token instead.

1 Like

Thanks @shrink, you’re right :muscle: . I was using github.token instead of secrets.ACCESS_TOKEN.

I was confused because the API endpoint response did not have an error.