Skip to content

Instantly share code, notes, and snippets.

@rajbos
Created May 28, 2023 20:54
Show Gist options
  • Save rajbos/e2e17b2aa24618339f8b22d75918484d to your computer and use it in GitHub Desktop.
Save rajbos/e2e17b2aa24618339f8b22d75918484d to your computer and use it in GitHub Desktop.
Post json with GitHub CLI

See more info in this discussion

For example, adding labels to a runner will fail:

gh api repos/rajbos/demo-actions/actions/runners/23/labels -f body="{\"labels\":[\"new-gpu\",\"accelerated\"]}"  

Response:

{ "message": "Invalid request.\n\nInvalid input: object is missing required key: labels.", "documentation_url": "https://docs.github.com/rest/reference/actions#add-custom-labels-to-a-self-hosted-runner-for-a-repository" } gh: Invalid request.

Invalid input: object is missing required key: labels. (HTTP 422)

Correct usage:

Set-Content example.txt '{"labels":["new-gpu","accelerated"]}'

gh api repos/rajbos/demo-actions/actions/runners/23/labels --input .\example.txt   
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment