Malhar Ujawane

Notes

Note·

TIL: URL-encode numericFilters in the Hacker News Algolia API

An unencoded > in the HN Algolia numericFilters param returns HTTP 400 HTML. curl -G with --data-urlencode fixes it.

The Hacker News Algolia API returns the front page as JSON with no key:

curl -s "https://hn.algolia.com/api/v1/search?tags=front_page&hitsPerPage=40"

Filtering by time and points is where it bit. numericFilters takes expressions like created_at_i>1792557652, and pasting that straight into the URL fails:

SINCE=$(( $(date +%s) - 172800 ))   # 48 hours ago
curl -s -o /dev/null -w "unencoded: HTTP %{http_code}\n" \
  "https://hn.algolia.com/api/v1/search?tags=story&numericFilters=created_at_i>$SINCE,points>150&hitsPerPage=50"
unencoded: HTTP 400

The body is an HTML “400 Bad Request” page, so a script that pipes it into json.load dies with JSONDecodeError: Expecting value, which hides the real cause.

The fix is to let curl encode the query with -G and --data-urlencode:

curl -sG "https://hn.algolia.com/api/v1/search" \
  --data-urlencode "tags=story" \
  --data-urlencode "numericFilters=created_at_i>$SINCE,points>150" \
  --data-urlencode "hitsPerPage=50" \
  -w "\nencoded: HTTP %{http_code}\n" -o hn48.json
python3 -c "
import json; d=json.load(open('hn48.json')); print(d['nbHits'],'hits')
for h in sorted(d['hits'],key=lambda h:-h['points'])[:3]: print(h['points'], h['title'])"
encoded: HTTP 200
57 hits
1080 PHP 8.2.35
1068 Quad9 (DNS Resolver) to Exit France
982 eMudhra to exit global SSL/TLS certificate business

Ran on 2026-10-23 at 10:10 IST with curl and Python 3.13. Points are a snapshot and will have moved. -G turns each --data-urlencode pair into a query string on a GET, so > goes out as %3E and the comma as %2C.

Get new posts in your inbox

© 2026 Malhar Ujawane. Built with Astro.