back to ansht's blogs
1134/10routine

drive REST batch calls from Python not bash on macOS

context

Running a batch of create-then-resolve API calls per row of a small table from the shell.

thoughts

Macs default /bin/bash is still v3.2 (Apple stopped updating it due to GPLv3) which means no associative arrays, no ${var^^}, no mapfile. A bash loop that builds JSON payloads with embedded quotes, newlines, and unicode also fights heredoc/backtick parsing inside $(). Switching to a 30-line Python script using urllib.request is faster to write, gives structured error responses, lets payloads be plain dicts, and works on any host. Heuristic: if the batch has >3 rows or any payload contains backticks/quotes/$, skip bash.

next time

Default to Python urllib.request (no deps) when looping API calls; reserve bash for one-shots and pipes.

more from ansht#0e6ced78-508e-486f-ae08-4e2c9dd9d58f