When you just want to spot-check rankings, pull related searches, or turn a list of keywords into a CSV, spinning up a Python project is overkill. Pairing curl with jq gives you a fast google search command line workflow straight in your shell.
The recipes below were verified on December 4, 2026 against /google/search using "trail running shoes" (8 organic results).
1. Export your key once and print TSV
Keep the API key in an environment variable so it stays out of shell scripts:
export SERPBASE_API_KEY='YOUR_API_KEY' curl -s -X POST 'https://api.serpbase.dev/google/search' \ -H 'Content-Type: application/json' \ -H "X-API-Key: $SERPBASE_API_KEY" \ -d '{"q":"trail running shoes","gl":"us","hl":"en","device":"desktop"}' \ | jq -r '.organic[] | "\(.rank)\t\(.title)\t\(.link)"' 2. Fail loudly in scripts with jq -e
The endpoint returns HTTP 200 even when a search fails; the real result sits in .status (0 = ok). Use jq -e with error(...) so failed queries return a non-zero exit code (5):
curl -s -X POST 'https://api.serpbase.dev/google/search' \ -H 'Content-Type: application/json' \ -H "X-API-Key: $SERPBASE_API_KEY" \ -d '{"q":"trail running shoes"}' \ | jq -e 'if .status == 0 then "ok, \(.organic | length) results" else error("failed: \(.status) \(.error)") end' 3. Safe shell helper + keywords.txt to CSV
Avoid hand-escaping quotes or non-ASCII characters in bash by building the JSON payload with jq -n --arg and piping it into curl -d @-:
gs() { jq -n --arg q "$1" '{q: $q, gl: "us", hl: "en", device: "desktop"}' \ | curl -s -X POST 'https://api.serpbase.dev/google/search' \ -H 'Content-Type: application/json' \ -H "X-API-Key: $SERPBASE_API_KEY" \ -d @- } # Related searches for a single query gs "trail running shoes" | jq -r '.related_searches[]' # Batch keywords.txt -> results.csv while IFS= read -r kw; do gs "$kw" | jq -r --arg kw "$kw" \ 'select(.status == 0) | .organic[] | [$kw, .rank, .title, .link] | @csv' sleep 1 done < keywords.txt > results.csv 4. Handy jq one-liners
jq -r '.organic[].link' # URLs only jq -r '.organic[].link | split("/")[2]' # Ranking domains jq -r '.people_also_ask[]?.question' # PAA questions (safe if missing) jq -r '.ai_overview.summary // empty' # AI Overview text (safe if missing) Four quick shell gotchas
- Always pass
-stocurlso progress meters do not corrupt piped JSON. - Guard optional sections (
people_also_ask,ai_overview) with[]?or// empty. - Add
sleep 1in loops to stay comfortably under rate limits. - Some
linkvalues come back asgoogle.com/goto?...redirects (5 of 8 in this run); readdisplay_linkif you only need the domain.
Full command examples and output notes: Google Search from the command line with curl and jq.


