I want to use CLI to do something lke a GDPR delete request. The JSON for the delete API needs the subject passed in like the userId. I'm hoping to be able to do something like a gc users list with a select/where clause and retrieve just the userIDs for users (from a specific division or group). I want to then be able to loop or do a for-each on each of those IDs. The problem is how can I pass that ID value through to the subsequent query?
Other that piping in a pre-set JSON file, can I pipe the JSON syntax through in-line somehow? Anybody got an example of how that might look?
To add to Ronan's answer, I'm not sure how you could achieve this with a single CLI command, but this bash script example could help:
gc users list | jq '[.entities | .[] | select(.division.id=="<division ID>") | .id]' | while read object; do
if [ "${object}" != "[" ] && [ "${object}" != "]" ]; then
ID=$(echo $object | sed 's/"//g')
ID=$(echo $ID | sed 's/,//g')
gc users get $ID
fi
done
If I'm not mistaken, your question is how could you treat the resulting JSON array as a bash array so you can use the items for more commands. The solution I found above is a bit messy but it works.