1

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

bazioles
  • 11
  • 3

1 Answers1

0

For beginners as I: I found a problem using set -x at the end of the script to see all called commands. There was /r added at the end of ids and this answer helped.

bazioles
  • 11
  • 3
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 06 '23 at 05:54