Github Actions: workflow not running from API call 'workflow_dispatch' trigger

I have a workflow in a private repository that is triggered on workflow_dispatch: image
When I send a request to the GitHub API of the form:

curl -u "$TOKEN:" \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/<my_org>/<repo_name>/actions/workflows/<workflow_id>/dispatches \
  -d '{"ref": "wip-ci", "inputs": {<my_inputs>}}'

nothing runs, or at least nothing comes up on the actions tab of the repo, and nothing is printed out in my terminal. Previously, when I was using an incorrect ref which did not have the workflow it would state that the workflow did not have a repository dispatch trigger. Why is my workflow not running and how can I debug this?

The workflow does run when I run it manually from GitHub.

Hi @Shamazo
I shared the following example in this scenario: I trigger workflowA(including a “Create a workflow dispatch event” ) with a push event. After workflowA runs successfully, workflowB will be triggered automatically.

workflowA.yml:

name: testAPI

on:
  push
  
jobs:
  build:
    runs-on: ubuntu-latest
    env:
      TOKEN: ${{ secrets.MY_GITHUB_PAT }}
    
    steps:
    - uses: actions/checkout@v2

    - name: run Api
      run: |
        curl -u ":$TOKEN" \
        -X POST \
        -H "Accept: application/vnd.github.v3+json" \
        https://api.github.com/repos/<your_org>/<repo_name>/actions/workflows/workflowB.yml/dispatches \
        -d '{"ref": "master", 
             "inputs": {
                "name": "trigger from api2",
                "home": "test2"}
        }'

workflowB.yml:

name: Manually triggered workflow
on:
  workflow_dispatch:
    inputs:
      name:
        description: 'Person to greet'
        required: true
        default: 'Mona the Octocat'
      home:
        description: 'location'
        required: false
jobs:
  say_hello:
    runs-on: ubuntu-latest
    steps:
    - run: |
        echo "Hello ${{ github.event.inputs.name }}!"
        echo "Hello ${{ github.event.inputs.home }}!"

Thank you for the example. My workflows are basically more complex versions of these two. My problem is that they run from the Github UI but not from an API request.

What kind of token are you using? A PAT or the GITHUB_TOKEN from another workflow? For the GITHUB_TOKEN the same restriction for other events applies - it cannot trigger another workflow to prevent infinite loops.

I am using a personal access token I generated and saved as a secret for the repository. The PAT has full permissions.

What response do you get from the API?

Using the verbose mode of CURL:

Note: Unnecessary use of -X or --request, POST is already inferred.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 140.82.114.5:443...
* TCP_NODELAY set
* Connected to api.github.com (140.82.114.5) port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /home/hamish/anaconda3/ssl/cacert.pem
  CApath: none
} [5 bytes data]
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* TLSv1.3 (IN), TLS handshake, Server hello (2):
{ [122 bytes data]
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
{ [25 bytes data]
* TLSv1.3 (IN), TLS handshake, Certificate (11):
{ [2975 bytes data]
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
{ [264 bytes data]
* TLSv1.3 (IN), TLS handshake, Finished (20):
{ [36 bytes data]
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
} [1 bytes data]
* TLSv1.3 (OUT), TLS handshake, Finished (20):
} [36 bytes data]
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: C=US; ST=California; L=San Francisco; O=GitHub, Inc.; CN=*.github.com
*  start date: Jun 22 00:00:00 2020 GMT
*  expire date: Aug 17 12:00:00 2022 GMT
*  subjectAltName: host "api.github.com" matched cert's "*.github.com"
*  issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA
*  SSL certificate verify ok.
} [5 bytes data]
> POST /repos/fractalcomputers/protocol/actions/workflows/proc-branch_build_release.yaml/dispatches HTTP/1.1
> Host: api.github.com
> User-Agent: curl/7.68.0
> authorization: Bearer de48e137545fe6da570811986beb5f4f690fe077
> Accept: application/vnd.github.v3+json
> Content-Length: 108
> Content-Type: application/x-www-form-urlencoded
> 
} [108 bytes data]
* upload completely sent off: 108 out of 108 bytes
{ [5 bytes data]
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
{ [57 bytes data]
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
{ [57 bytes data]
* old SSL session ID is stale, removing
{ [5 bytes data]
* Mark bundle as not supporting multiuse
< HTTP/1.1 204 No Content
< Server: GitHub.com
< Date: Tue, 28 Jul 2020 19:37:53 GMT
< Status: 204 No Content
< X-RateLimit-Limit: 60
< X-RateLimit-Remaining: 57
< X-RateLimit-Reset: 1595968621
< X-OAuth-Scopes: repo
< X-Accepted-OAuth-Scopes: 
< X-GitHub-Media-Type: github.v3; format=json
< Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset
< Access-Control-Allow-Origin: *
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< X-Frame-Options: deny
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Content-Security-Policy: default-src 'none'
< Vary: Accept-Encoding, Accept, X-Requested-With
< X-GitHub-Request-Id: B586:14D8:8E1A9:17AA06:5F207E91
< 

100   108    0     0  100   108      0    421 --:--:-- --:--:-- --:--:--   421
* Connection #0 to host api.github.com left intact

Nothing from non-verbose. Which seems to be the expected response for a successful request, except that the workflow does not seem to be running.

Hi @Shamazo
If you go to actions tab page >> click ” Run workflow“ >> select branch, could you find “wip-ci” in the branch list?


I can trigger the workflow both through another workflow(including a “Create a workflow dispatch event ” ) or run the command locally. It may be that my operation and environment are different from yours, which leads to I can’t reproduce this issue. So I would appreciate it if you could provide some screenshots about your steps. Thanks.