Skip to content

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

Instagram Scraper API by ScrapeBadger

Get API key Docs MCP server Pricing

Instagram Scraper API

Get public Instagram data as JSON with one HTTP request. The Instagram Scraper API returns public profiles with follower counts, posts and reels with captions and engagement, comments, related accounts, hashtag pages and search for users, hashtags and top results. This repo has a runnable Python, Node.js and cURL example for the main endpoints and the real response each one returned.

What does an Instagram scraper do?

An Instagram scraper collects data from public Instagram profiles and posts, such as bios, follower counts, captions, likes, comments, hashtags and reel views, and returns it as structured data. Brands use it to vet influencers and track campaigns, and analysts use it to follow competitors and trends. With this API you send a username, post shortcode or hashtag and get JSON back.

Contents

Quick start

  1. Create a free ScrapeBadger account. You get 1,000 free credits, no card needed.

  2. Copy your API key from the dashboard and export it:

    export SCRAPEBADGER_API_KEY="your_api_key"
  3. Make your first request: get a profile.

cURL

curl -sS --max-time 120 -G "https://scrapebadger.com/v1/instagram/users/nasa" \
  -H "X-API-Key: $SCRAPEBADGER_API_KEY"

Python (pip install requests)

import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

username = "nasa"

response = requests.get(
    f"https://scrapebadger.com/v1/instagram/users/{username}",
    headers={"X-API-Key": API_KEY},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js (18+, no dependencies)

const username = 'nasa';

const response = await fetch(`https://scrapebadger.com/v1/instagram/users/${encodeURIComponent(username)}`, {
  headers: { 'X-API-Key': process.env.SCRAPEBADGER_API_KEY },
  signal: AbortSignal.timeout(120000),
});
if (!response.ok) {
  throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
console.log(JSON.stringify(await response.json(), null, 2));

Every endpoint below has the same three versions in examples/, and the real response it returned is in output-samples/.

Endpoints

Base URL: https://scrapebadger.com. Authenticate with the X-API-Key header. Credits are charged only for successful requests.

Endpoint What it returns Credits per request Docs
GET /v1/instagram/users/{username} Get profile 8 Docs
GET /v1/instagram/users/{username}/about About this account 8
GET /v1/instagram/users/{username}/related Related profiles 8
GET /v1/instagram/users/{username}/posts Get user posts 12 Docs
GET /v1/instagram/users/{username}/reels Get user reels 12
GET /v1/instagram/users/{username}/tagged Get tagged posts 12
GET /v1/instagram/users/{username}/followers Get followers 15
GET /v1/instagram/users/{username}/following Get following 15
GET /v1/instagram/users/{username}/stories Get active stories 23
GET /v1/instagram/users/{username}/highlights Get highlights 23
GET /v1/instagram/media/{code} Get post/reel detail 8 Docs
GET /v1/instagram/media/{code}/comments Get comments 12 Docs
GET /v1/instagram/media/{code}/likers Get likers 12
GET /v1/instagram/hashtags/{tag} Get hashtag info 8 Docs
GET /v1/instagram/hashtags/{tag}/top Top hashtag posts 12
GET /v1/instagram/hashtags/{tag}/recent Recent hashtag posts 12
GET /v1/instagram/locations/{location_pk} Get location 8
GET /v1/instagram/search/users Search users 8
GET /v1/instagram/search/top Blended top search 8 Docs
GET /v1/instagram/search/hashtags Search hashtags 3
GET /v1/instagram/audio/{audio_id} Get audio track 8

Common parameters

Parameter Description Default
amount How many items to return on list endpoints (posts, reels, comments, hashtag posts). 20
cursor Cursor from the previous response, to get the next page.

Examples by endpoint

Each example prints the JSON response. The Python versions are below; Node.js and cURL versions are linked under each one.

Get a profile

Full public profile: bio, counts, verification, business contact, links.

GET /v1/instagram/users/{username} · Credits: 8 · Docs

Parameter Required Type Default Description
username Yes string Instagram username without @, e.g. nasa
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

username = "nasa"

response = requests.get(
    f"https://scrapebadger.com/v1/instagram/users/{username}",
    headers={"X-API-Key": API_KEY},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (5 KB)

Get a user's posts

Timeline posts, paginated.

GET /v1/instagram/users/{username}/posts · Credits: 12 · Docs

Parameter Required Type Default Description
username Yes string Instagram username without @, e.g. nasa
amount integer 20 How many items to return on list endpoints (posts, reels, comments, hashtag posts).
cursor string Cursor from the previous response, to get the next page.
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

username = "nike"

response = requests.get(
    f"https://scrapebadger.com/v1/instagram/users/{username}/posts",
    headers={"X-API-Key": API_KEY},
    params={
        "amount": 6,
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (115 KB)

Get a user's reels

GET /v1/instagram/users/{username}/reels · Credits: 12

Parameter Required Type Default Description
username Yes string Instagram username without @, e.g. nasa
amount integer 20 How many items to return on list endpoints (posts, reels, comments, hashtag posts).
cursor string Cursor from the previous response, to get the next page.
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

username = "nasa"

response = requests.get(
    f"https://scrapebadger.com/v1/instagram/users/{username}/reels",
    headers={"X-API-Key": API_KEY},
    params={
        "amount": 6,
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (123 KB)

Get a post or reel

Single post or reel: caption, media, counts, tags, location, carousel.

GET /v1/instagram/media/{code} · Credits: 8 · Docs

Parameter Required Type Default Description
code Yes string Post or reel shortcode, the part after /p/ or /reel/ in a URL, e.g. Dbqyg11kVWo
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

code = "Dbqyg11kVWo"

response = requests.get(
    f"https://scrapebadger.com/v1/instagram/media/{code}",
    headers={"X-API-Key": API_KEY},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (16 KB)

Get comments on a post

GET /v1/instagram/media/{code}/comments · Credits: 12 · Docs

Parameter Required Type Default Description
code Yes string Post or reel shortcode, the part after /p/ or /reel/ in a URL, e.g. Dbqyg11kVWo
amount integer 20 How many items to return on list endpoints (posts, reels, comments, hashtag posts).
cursor string Cursor from the previous response, to get the next page.
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

code = "Dbqyg11kVWo"

response = requests.get(
    f"https://scrapebadger.com/v1/instagram/media/{code}/comments",
    headers={"X-API-Key": API_KEY},
    params={
        "amount": 5,
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (42 KB)

Get related profiles

GET /v1/instagram/users/{username}/related · Credits: 8

Parameter Required Type Default Description
username Yes string Instagram username without @, e.g. nasa
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

username = "nasa"

response = requests.get(
    f"https://scrapebadger.com/v1/instagram/users/{username}/related",
    headers={"X-API-Key": API_KEY},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (89 KB)

Get hashtag info

GET /v1/instagram/hashtags/{tag} · Credits: 8 · Docs

Parameter Required Type Default Description
tag Yes string Hashtag without #, e.g. travel
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

tag = "travel"

response = requests.get(
    f"https://scrapebadger.com/v1/instagram/hashtags/{tag}",
    headers={"X-API-Key": API_KEY},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (1 KB)

Search users

GET /v1/instagram/search/users · Credits: 8

Parameter Required Type Default Description
query Yes string
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.get(
    "https://scrapebadger.com/v1/instagram/search/users",
    headers={"X-API-Key": API_KEY},
    params={
        "query": "nasa",
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (27 KB)

Search hashtags

GET /v1/instagram/search/hashtags · Credits: 3

Parameter Required Type Default Description
query Yes string
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.get(
    "https://scrapebadger.com/v1/instagram/search/hashtags",
    headers={"X-API-Key": API_KEY},
    params={
        "query": "travel",
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (2 KB)

Example output

A real response from GET /v1/instagram/users/{username}, trimmed to the first items of each list. The full response is in output-samples/profile.json.

{
  "pk": "528817151",
  "username": "nasa",
  "full_name": "NASA",
  "is_private": false,
  "profile_pic_url": "https://instagram.fgdl5-2.fna.fbcdn.net/v/t51.2885-19/29090066_159271188110124_1152068159029641216_n.jpg?stp=dst-jpg_e0_s150x150_tt6&_nc_cat=1&ig_cache_key=GBLhuwEsG5c225AAAAAAAADj9-wPbkULAAAB1501500j-ccb7-5&ccb=7-5&_nc_…",
  "profile_pic_url_hd": "https://instagram.fgdl5-2.fna.fbcdn.net/v/t51.2885-19/29090066_159271188110124_1152068159029641216_n.jpg?stp=dst-jpg_s640x640_tt6&efg=eyJ2ZW5jb2RlX3RhZyI6InByb2ZpbGVfcGljLmRqYW5nby4xMDgwLmMyIn0&_nc_ht=instagram.fgdl5-2.f…",
  "is_verified": true,
  "media_count": 5036,
  "follower_count": 104246485,
  "following_count": 91,
  "biography": "Making the seemingly impossible, possible. ✨",
  "bio_links": [
    {
      "link_id": "17920263086752176",
      "url": "https://www.nasa.gov",
      "lynx_url": "https://l.instagram.com/?u=https%3A%2F%2Fwww.nasa.gov%2F%3Futm_source%3Dig%26utm_medium%3Dsocial%26utm_content%3Dlink_in_bio%26fbclid%3DPAZXh0bgNhZW0CMTEAcGRvZgJzcnRjBmFwcF9pZA81NjcwNjczNDMzNTI0MjcAAaeAGmCzJlPTQaD-eUiPTy…",
      "link_type": "external",
      "title": "NASA.gov Homepage",
      "is_pinned": false,
      "open_external_url_with_in_app_browser": true
    },
    {
      "link_id": "1034821412909488",
      "url": "https://science.nasa.gov/feature/artemis-ii-preliminary-lunar-science-report/",
      "lynx_url": "https://l.instagram.com/?u=https%3A%2F%2Fscience.nasa.gov%2Ffeature%2Fartemis-ii-preliminary-lunar-science-report%2F%3Futm_source%3Dig%26utm_medium%3Dsocial%26utm_content%3Dlink_in_bio%26fbclid%3DPAZXh0bgNhZW0CMTEAcGRvZg…",
      "link_type": "external",
      "title": "Artemis II Preliminary Lunar Science Report",
      "is_pinned": false,
      "open_external_url_with_in_app_browser": true
    }
  ],
  "external_url": "https://www.nasa.gov",
  "show_text_post_app_badge": true,
  "text_post_app_badge_label": "nasa",
  "account_type": 2,
  "is_business": true,
  "broadcast_channel": [],
  "public_email": "public-inquiries@hq.nasa.gov",
  "contact_phone_number": null,
  "public_phone_country_code": "",
  "public_phone_number": "",
  "business_contact_method": "CALL",
  "business_category_name": null,
  "category_name": null,
  "category": "",
  "address_street": "",
  "city_id": "0",
  "city_name": "",
  "latitude": 0.0,
  "longitude": 0.0,
  "zip": "",
  "instagram_location_id": "54971236771",
  "interop_messaging_user_fbid": "118750106179205"
}

Use it with AI agents (MCP)

ScrapeBadger runs a hosted MCP server, so Claude, Cursor, ChatGPT and other agents can call the Instagram endpoints as tools, with no code.

  • Claude (claude.ai or Claude Desktop): Settings → Connectors → Add custom connector → https://mcp.scrapebadger.com/mcp, then sign in. No API key needed.
  • Cursor, VS Code, Windsurf and other clients: add this server to your MCP config:
{
  "mcpServers": {
    "scrapebadger": {
      "url": "https://mcp.scrapebadger.com/mcp?apis=instagram",
      "headers": { "Authorization": "Bearer YOUR_SCRAPEBADGER_API_KEY" }
    }
  }
}

Then ask:

Compare the last 6 posts of @nike and @adidas on Instagram by likes and comments, and tell me which content type performs best.

Setup guides for each client are in the MCP docs.

Use cases

Use case What you collect Endpoints
Influencer vetting Followers, engagement per post and reel views for any public creator Get a profile, Get a user's posts, Get a user's reels
Competitor tracking What competitors post, how often, and how it performs Get a user's posts, Get a user's reels, Get a post or reel
Comment and sentiment analysis Comments on campaign posts, for sentiment and questions Get comments on a post
Hashtag research How many posts use a hashtag, and related hashtags for a keyword Get hashtag info, Search hashtags
Creator discovery Accounts similar to one you like, and accounts matching a keyword Get related profiles, Search users

Pricing

  • Each endpoint's credit cost is listed in the endpoints table.
  • Only successful requests are billed. Blocked, empty and failed results cost nothing.
  • New accounts get 1,000 free credits. After that, pay as you go or pick a monthly plan. Credits on pay-as-you-go never expire.

See ScrapeBadger pricing for the price per credit on each plan.

Errors

Errors come back as JSON with a detail field (and an error code on some).

Status Meaning What to do
400 / 422 A parameter is missing or invalid Check the parameter table for the endpoint
401 Missing, invalid or expired API key Send the key in the X-API-Key header
402 Out of credits Top up or upgrade in the dashboard
403 The key can't call this API, or the request came from an IP the key doesn't allow Check the key's scopes and IP allowlist
404 The item, page or profile doesn't exist (or is no longer public) Check the ID; not billed
429 Over your account's max concurrency Wait Retry-After (1 s) and retry; run fewer calls in parallel (concurrency)
502 / 503 / 504 The target site failed or timed out on this attempt Not billed. Retry with backoff

Long calls can run asynchronously: send Prefer: respond-async and poll the returned request_id (async requests).

FAQ

Is it legal to scrape Instagram?

This API only returns data from public profiles and posts, which anyone can see. Collecting public data is generally lawful in most jurisdictions, but profiles and comments contain personal data, so check the rules that apply to how you store and use it (for example GDPR), and ask a lawyer if you're unsure. Private accounts are not available.

What Instagram data can I get?

Public profiles (bio, follower and following counts, verification, links), posts and reels with captions, likes, comments and views, comments on a post, related profiles, hashtag pages, and search for users and hashtags. See the endpoints table.

How much does it cost?

Each request costs a fixed number of credits, shown in the endpoints table, and only successful requests are billed. You get 1,000 free credits when you sign up, then pay as you go or pick a plan on the pricing page.

Do I need an Instagram account or the Graph API?

No. You only need a ScrapeBadger API key. The Instagram Graph API only covers accounts you manage; this API reads any public profile.

How fast is it, and are there rate limits?

Most calls answer in a few seconds. There's no per-minute cap: you can run as many requests in parallel as your plan's max concurrency allows, and a request over it gets 429 without being billed.

Other languages

These examples use plain HTTP. Official SDKs wrap every endpoint with types and retries:

Language Repository Install
Python scrape-badger/scrapebadger-python pip install scrapebadger
Node.js / TypeScript scrape-badger/scrapebadger-node npm install scrapebadger
Go scrape-badger/scrapebadger-go
Java scrape-badger/scrapebadger-java
C# scrape-badger/scrapebadger-csharp
PHP scrape-badger/scrapebadger-php
Ruby scrape-badger/scrapebadger-ruby
Rust scrape-badger/scrapebadger-rust
Kotlin scrape-badger/scrapebadger-kotlin
Swift scrape-badger/scrapebadger-swift
Dart scrape-badger/scrapebadger-dart
C++ scrape-badger/scrapebadger-cpp

There is also a CLI (pip install scrapebadger-cli) and an n8n node.

Related scrapers

Learn more

Disclaimer

ScrapeBadger is an independent tool and is not affiliated with, endorsed by, or sponsored by Instagram, LLC or any of its subsidiaries or affiliates. "Instagram" is a trademark of Instagram, LLC, used here only to describe the platform this scraper works with. This repository only covers publicly available data. You are responsible for how you use the data you collect and for following the laws that apply to you.

License

MIT. The examples are free to copy into your own projects.