VaunMcCarthy | 2022-08-03 03:52:52 UTC | #1
Not sure how to word this but....
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?
anon11147534 | 2022-08-03 11:40:08 UTC | #2
Hi,
To pipe inline without a JSON file you could use a command such as the following:
echo '{"name": "test cli user", "email": "test_cli_user@test.com"}' | gc users create
charlie.conneely | 2022-08-08 13:01:55 UTC | #3
Hi,
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.
Regards
VaunMcCarthy | 2022-08-03 19:49:09 UTC | #4
Thanks Ronan, and Charlie
Unless I've missed it, this would be handy to have in the CLI documentation.
system | 2022-09-02 19:50:00 UTC | #5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 15767