You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Neither --field nor --raw-field accept JSON arrays right now. To pass a JSON array or a nested object, one needs to construct the JSON payload outside of gh and pass it in via --input. E.g.
jq -n '...'| gh api repos/:owner/:repo/deployments --input -
I propose a new array syntax for fields:
# array of strings
-f labels[]=one labels[]=two
# empty array
-f required_contexts[]
# other value types
-F foo[]=true -F bar[]=null
This syntax would allow passing values of any type, including an empty array, and is fully backwards-compatible. The only theoretical drawback is that it would be impossible to pass a parameter name that includes the literal [] characters, but since no API parameters ever have [] characters in their name, I think this is not a concern.
Reacted by Nate Smith, Roger D. Winans, Benjamin Levesque, Bob Bell, Tim Littlemore, Futa HIRAKOBA, Alexey Alekhin, Katsuya HIDAKA, Jason Karns, Bartłomiej Kalemba and 24 more
Neither --field nor --raw-field accept JSON arrays right now. To pass a JSON array or a nested object, one needs to construct the JSON payload outside of gh and pass it in via --input. E.g.
jq -n '...' | gh api repos/:owner/:repo/deployments --input -
I had in mind gh would default to GET for this request.
The fact that gh automatically switches to POST once -f or -F is added is a decision I now regret for its magic-ness 🙈 but we can't back out of it easily due to backwards-compatibility.
Hit same issue and spend one hour mapping the OpenAPI spec against gh behavior and was wondering why arrays/objects are not supported, e.g.:
# does not work
gh api repos/:owner/:repo/issues/1/labels -f labels='["wontfix"]'# works
jq -n '{"labels":["wontfix"]}'| gh api repos/:owner/:repo/issues/1/labels --input -
Will file a PR because this behavior is not clear from the docs Pass one or more --raw-field values in "key=value" format to add **JSON-encoded string parameters** to the POST body..
Reacted by Alexey Alekhin, Doug Ayers, Eva Maxfield Brown, Mauro Baluda and navrkald
This still seems to be an issue - you can't configure check contexts when setting up branch protection because of this. 😞
I think this issue is missing a label of ~bug ?
I was able to get this to work, but the syntax was not immediately apparent. Here is an example:
gh api -X PUT /repos/zoomin-software/skins_foo/branches/development/protection -F restrictions=null -F enforce_admins=true -F 'required_pull_request_reviews[require_code_owner_reviews]=true' -F 'required_status_checks[strict]=true' -F 'required_status_checks[contexts][]=null'
Note the last param I pass: -F 'required_status_checks[contexts][]=null', with the second array within the array, but the value being null. This is how I was able to pass an "empty" array.
Activity
mislav commentedon Aug 6, 2020
Potential additional idea: use a similar syntax to pass nested objects as well, since some APIs require them as inputs. For example, the Gist API:
I'm not sure if this is a crossing a line into too magic or complicated 😅
solvaholic commentedon Dec 31, 2020
I'm trying to GET the
repos/:owner/:repo/contentsendpoint with a specificref.This command returns the file content as expected 🎉:
When I provide the
refparameter, however, I get 404 😢:I assume I'm missing something that'll be obvious to others. @mislav do you see what I'm missing? Or have suggestions how to debug this?
joe-sharp commentedon Jan 22, 2021
@solvaholic Not sure if you solved this already but according to the doc you linked, ref is a query parameter. So you would need to do this:
gh api repos/:owner/:repo/contents/action.yml?ref=mainYou may need to quote it:
gh api 'repos/:owner/:repo/contents/action.yml?ref=main'mislav commentedon Jan 22, 2021
Parameters given via
--field/--raw-fieldcan also be forced to be query parameters by explicitly configuring the method to be GET:solvaholic commentedon Jan 25, 2021
:doh: I'm near certain this was a factor when I tried adding the query parameter.
And this as well. I had in mind
ghwould default to GET for this request.Of course, both methods work. Thank you @joe-sharp @mislav 🙇
mislav commentedon Jan 25, 2021
The fact that gh automatically switches to POST once
-for-Fis added is a decision I now regret for its magic-ness 🙈 but we can't back out of it easily due to backwards-compatibility.ErikSchierboom commentedon Apr 7, 2021
I've managed to workaround this via the
--inputparameter. It would be awesome if arrays could be supported via the--field/--raw-fieldsyntax too.embano1 commentedon Apr 12, 2021
Hit same issue and spend one hour mapping the OpenAPI spec against
ghbehavior and was wondering why arrays/objects are not supported, e.g.:Will file a PR because this behavior is not clear from the docs
Pass one or more --raw-field values in "key=value" format to add **JSON-encoded string parameters** to the POST body..Add note on supported value types in raw-fields
Add note on supported value types in raw-fields
Revert 6e7adb3
sammcj commentedon Oct 5, 2022
This still seems to be an issue - you can't configure check contexts when setting up branch protection because of this. 😞
I think this issue is missing a label of ~bug ?
.github/workflows: trigger interop test with `gh`
pzoomin commentedon Mar 18, 2024
I was able to get this to work, but the syntax was not immediately apparent. Here is an example:
gh api -X PUT /repos/zoomin-software/skins_foo/branches/development/protection -F restrictions=null -F enforce_admins=true -F 'required_pull_request_reviews[require_code_owner_reviews]=true' -F 'required_status_checks[strict]=true' -F 'required_status_checks[contexts][]=null'Note the last param I pass:
-F 'required_status_checks[contexts][]=null', with the second array within the array, but the value beingnull. This is how I was able to pass an "empty" array.