Instagram and TikTok API with cURL
Every route works from a terminal: one header, JSON back. Add jq and a short loop to page through any list and save it as JSON Lines or CSV.
Short answer. curl -sS --fail --retry 3 "https://api.handlehaul.com/v1/tiktok/users/mila.studio" -H "X-Api-Key: $HANDLEHAUL_API_KEY". For lists, repeat with --data-urlencode "cursor=…" until pagination.next_cursor is null, as the script below does.
Facts checked 2 December 2026. Prices change: follow the links before you decide.
Flags that matter
--retry 3: curl 7.66 or newer retries a429and waits for itsRetry-After; 429 answers are free.--fail: exits with code 22 on an error instead of printing the error body as if it were data. Drop it, or use--fail-with-body(curl 7.76+), when you want to readerror.code.-G --data-urlencode "q=...": builds the query string and encodes links and spaces for you, which matters forurl=and search terms.-ishows the headers:X-Credits-Charged,X-HandleHaul-Cache(HIT or MISS) andX-RateLimit-Remaining.
Page any list to JSON Lines
The script takes a path and a page limit, prints one row per line on stdout and the credits used on stderr, so > rows.jsonl saves just the data. Needs jq.
To CSV: ./handlehaul-pages.sh /instagram/users/natgeo/followers 4 | jq -r '[.position, .username, .full_name] | @csv' > followers.csv.
handlehaul-pages.shInstall: brew install jq (or apt install jq)Run: ./handlehaul-pages.sh /instagram/users/natgeo/followers 3
#!/usr/bin/env bash
# Every page of a HandleHaul list endpoint with curl + jq, as one JSON object per line (JSON Lines).
# export HANDLEHAUL_API_KEY=kd_live_... # or a free kd_test_ key for sample data
# ./handlehaul-pages.sh /instagram/users/natgeo/followers 3 > followers.jsonl
set -euo pipefail
path="${1:?usage: $0 <path, e.g. /instagram/users/natgeo/followers> [max pages]}"
max_pages="${2:-3}"
url="https://api.handlehaul.com/v1${path}"
cursor=""
credits=0
for ((page = 1; page <= max_pages; page++)); do
args=(-sS --fail --retry 3 -G "$url" -H "X-Api-Key: $HANDLEHAUL_API_KEY")
if [ -n "$cursor" ]; then
args+=(--data-urlencode "cursor=$cursor")
fi
body=$(curl "${args[@]}") # --retry waits out a 429 (Retry-After)
jq -c '.data[]' <<<"$body" # one row per line on stdout
credits=$((credits + $(jq '.meta.credits_charged' <<<"$body")))
cursor=$(jq -r '.pagination.next_cursor // empty' <<<"$body")
[ -z "$cursor" ] && break
done
echo "pages: $((page > max_pages ? max_pages : page)), credits used: $credits" >&2
Every endpoint in cURL
Each page below has a complete cURL program for one route, the parameters, a sample response and what it costs. The link opens the cURL tab.
| Tutorial | Route |
|---|---|
| Profile | GET /v1/instagram/users/{user} |
| Account details | GET /v1/instagram/users/{user}/account-details |
| Similar accounts | GET /v1/instagram/users/{user}/related |
| Followers | GET /v1/instagram/users/{user}/followers |
| Following | GET /v1/instagram/users/{user}/following |
| Posts | GET /v1/instagram/users/{user}/posts |
| Reels | GET /v1/instagram/users/{user}/reels |
| Tagged posts | GET /v1/instagram/users/{user}/tagged |
| Reposts | GET /v1/instagram/users/{user}/reposts |
| Post or reel | GET /v1/instagram/posts/{post} |
| Post stats (batch) | GET /v1/instagram/posts/stats |
| Comments | GET /v1/instagram/posts/{post}/comments |
| Comment replies | GET /v1/instagram/comments/{comment}/replies |
| Post likers | GET /v1/instagram/posts/{post}/likers |
| Comment likers | GET /v1/instagram/comments/{comment}/likers |
| Stories | GET /v1/instagram/users/{user}/stories |
| Story by id | GET /v1/instagram/stories/{story} |
| Highlights | GET /v1/instagram/users/{user}/highlights |
| Highlight stories | GET /v1/instagram/highlights/{highlight} |
| Search hashtags | GET /v1/instagram/search/hashtags |
| Hashtag | GET /v1/instagram/hashtags/{tag} |
| Hashtag posts | GET /v1/instagram/hashtags/{tag}/posts |
| Search places | GET /v1/instagram/search/places |
| Place | GET /v1/instagram/places/{place} |
| Place posts | GET /v1/instagram/places/{place}/posts |
| Search audio | GET /v1/instagram/search/audio |
| Trending audio | GET /v1/instagram/audio/trending |
| Audio | GET /v1/instagram/audio/{audio} |
| Reels using audio | GET /v1/instagram/audio/{audio}/reels |
| Search accounts | GET /v1/instagram/search/users |
| URL resolver | GET /v1/instagram/resolve |
TikTok
| Tutorial | Route |
|---|---|
| Profile | GET /v1/tiktok/users/{user} |
| Suggested accounts | GET /v1/tiktok/users/{user}/suggested |
| Followers | GET /v1/tiktok/users/{user}/followers |
| Following | GET /v1/tiktok/users/{user}/following |
| Posts | GET /v1/tiktok/users/{user}/posts |
| Reposts | GET /v1/tiktok/users/{user}/reposts |
| Liked videos | GET /v1/tiktok/users/{user}/liked |
| Playlists | GET /v1/tiktok/users/{user}/playlists |
| Stories | GET /v1/tiktok/users/{user}/stories |
| Video or photo post | GET /v1/tiktok/posts/{post} |
| Comments | GET /v1/tiktok/posts/{post}/comments |
| Comment replies | GET /v1/tiktok/comments/{comment}/replies |
| Transcript | GET /v1/tiktok/posts/{post}/transcript |
| Sound | GET /v1/tiktok/music/{music} |
| Posts using a sound | GET /v1/tiktok/music/{music}/posts |
| Hashtag | GET /v1/tiktok/hashtags/{tag} |
| Hashtag posts | GET /v1/tiktok/hashtags/{tag}/posts |
| Search | GET /v1/tiktok/search |
cURL: questions
How do I test the API with cURL before paying?
kd_test_ key in the dashboard: it returns sample data in the live shape for free. Special usernames test errors: private_anything answers 403 private_account, ghost_anything 404 user_not_found.Is there a CLI instead of raw cURL?
npx handlehaul instagram followers natgeo --pages 3 (from the npm package). It reads HANDLEHAUL_API_KEY and prints JSON or JSON Lines.Why does my shell loop print an error JSON in the middle?
--fail, curl prints the body of a 429 before it retries. Add --fail so only successful answers reach jq.Related
Instagram and TikTok API in Python
Two ways to call HandleHaul from Python: a 60-line client on requests that you own, or the official handlehaul package (sync and async).
Read more →Instagram and TikTok API in Node.js
Call HandleHaul from Node.js 18 or newer with the built-in fetch, or install the typed handlehaul package from npm, which also ships a CLI.
Read more →Instagram and TikTok API in PHP
One class, PHP 8 and the curl extension: no Composer package needed.
Read more →Build it in cURL
One key for Instagram and TikTok. $1.40 to $0.80 per 1,000 calls; failed calls and cache hits are free.
Want to test first? Sandbox keys are free and unlimited, with sample data in the live schema.