Tutorial · cURL

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 a 429 and waits for its Retry-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 read error.code.
  • -G --data-urlencode "q=...": builds the query string and encodes links and spaces for you, which matters for url= and search terms.
  • -i shows the headers: X-Credits-Charged, X-HandleHaul-Cache (HIT or MISS) and X-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
Tested 2026-12-02 against a local mock serving the documented API responses (retry on 429, cursor paging, a private-account error).

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.

Instagram

Instagram endpoint tutorials
TutorialRoute
ProfileGET /v1/instagram/users/{user}
Account detailsGET /v1/instagram/users/{user}/account-details
Similar accountsGET /v1/instagram/users/{user}/related
FollowersGET /v1/instagram/users/{user}/followers
FollowingGET /v1/instagram/users/{user}/following
PostsGET /v1/instagram/users/{user}/posts
ReelsGET /v1/instagram/users/{user}/reels
Tagged postsGET /v1/instagram/users/{user}/tagged
RepostsGET /v1/instagram/users/{user}/reposts
Post or reelGET /v1/instagram/posts/{post}
Post stats (batch)GET /v1/instagram/posts/stats
CommentsGET /v1/instagram/posts/{post}/comments
Comment repliesGET /v1/instagram/comments/{comment}/replies
Post likersGET /v1/instagram/posts/{post}/likers
Comment likersGET /v1/instagram/comments/{comment}/likers
StoriesGET /v1/instagram/users/{user}/stories
Story by idGET /v1/instagram/stories/{story}
HighlightsGET /v1/instagram/users/{user}/highlights
Highlight storiesGET /v1/instagram/highlights/{highlight}
Search hashtagsGET /v1/instagram/search/hashtags
HashtagGET /v1/instagram/hashtags/{tag}
Hashtag postsGET /v1/instagram/hashtags/{tag}/posts
Search placesGET /v1/instagram/search/places
PlaceGET /v1/instagram/places/{place}
Place postsGET /v1/instagram/places/{place}/posts
Search audioGET /v1/instagram/search/audio
Trending audioGET /v1/instagram/audio/trending
AudioGET /v1/instagram/audio/{audio}
Reels using audioGET /v1/instagram/audio/{audio}/reels
Search accountsGET /v1/instagram/search/users
URL resolverGET /v1/instagram/resolve

TikTok

TikTok endpoint tutorials
TutorialRoute
ProfileGET /v1/tiktok/users/{user}
Suggested accountsGET /v1/tiktok/users/{user}/suggested
FollowersGET /v1/tiktok/users/{user}/followers
FollowingGET /v1/tiktok/users/{user}/following
PostsGET /v1/tiktok/users/{user}/posts
RepostsGET /v1/tiktok/users/{user}/reposts
Liked videosGET /v1/tiktok/users/{user}/liked
PlaylistsGET /v1/tiktok/users/{user}/playlists
StoriesGET /v1/tiktok/users/{user}/stories
Video or photo postGET /v1/tiktok/posts/{post}
CommentsGET /v1/tiktok/posts/{post}/comments
Comment repliesGET /v1/tiktok/comments/{comment}/replies
TranscriptGET /v1/tiktok/posts/{post}/transcript
SoundGET /v1/tiktok/music/{music}
Posts using a soundGET /v1/tiktok/music/{music}/posts
HashtagGET /v1/tiktok/hashtags/{tag}
Hashtag postsGET /v1/tiktok/hashtags/{tag}/posts
SearchGET /v1/tiktok/search

cURL: questions

How do I test the API with cURL before paying?
Create a 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?
Yes: 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?
Without --fail, curl prints the body of a 429 before it retries. Add --fail so only successful answers reach jq.

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.