Curl api on for loop doesn't work

Inspect the body of the response for additional information.

Check the URL that is being constructed is the correct/expected/valid URL

I modified your code off the top of my head and didn’t test it myself, since I don’t have your DB structure.