I have the following problem.
In the first curl query assigned to the list_json
variable, I get a list of objects in json format.
Then, based on the id's extracted from this list, I want to delete all the elements I retrieved.
My script unfortunately only works for the last element and as a result I have to repeat it n times to empty the whole list.
Why is this happening, where is the error occurring? I'll add that the same loop using echo
instead of curl ...
correctly displays all urls with ids, which works as expected using postman. That means ids are available, so why are they not deleted?
My script:
#!/usr/bin/env bash
API_PATH="http://local:8080/api/elements"
list_json=$(curl -s $API_PATH)
for element_id in $(echo ${list_json[@]} | jq -r '.[].id')
do
curl -X DELETE ${API_PATH}${element_id}
done
Any hints welcome. Greetings