Why does my cURL request display output when deleting records?

April 21, 2025 2 answers
Asked by unsorted drawers
I'm currently working on an API integration with Cloudflare, and I'm running into a bit of confusion. I have this cURL command that's almost directly taken from the documentation: ```bash curl "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records?per_page=50000" -4 --silent --header "X-Auth-Email: $email" --header "X-Auth-Key: $key" | jq -r '.result[].id' | while read id do curl -4 --request DELETE --url "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$id" --silent --header "X-Auth-Email: $email" --header "X-Auth-Key: $key" done ``` I linked the documentation here for reference: [Cloudflare API](https://developers.cloudflare.com/api/resources/dns/subresources/records/methods/delete/) My issue is that when I delete a record, it's printing the output on the screen like this: ```json {"result":{"id":"foo"},"success":true,"errors":[],"messages":[]} ``` I know I can add `> /dev/null 2>&1` to the end of the second cURL command inside the loop to suppress output, but I'm puzzled why it's displaying this output in the first place. Why do some cURL statements output to the screen while others do not?

Answers

halfback
Exactly! The first cURL sends its results to `jq` which processes the data without displaying it. In contrast, the second cURL is directly printing the result to stdout since it's not being piped or redirected. If you want to see any errors and still suppress normal output, using `> /dev/null 2>&1` will silence everything except error messages. Alternatively, you could redirect to `jq` in the loop to check the success status without cluttering your screen with output.
Reply to this answer
whats the verdict
The reason the first cURL command doesn't print output to the screen is that it's being piped to `jq`, which processes and filters the output. On the other hand, the second cURL within the loop is outputting to stdout directly, which is why you see the results. The `--silent` option only suppresses the progress display, not the actual response from the server. If you want to avoid seeing the output from the delete operations, you can redirect it to `/dev/null` or pipe it to `jq` to handle the output and capture potential errors.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions