Tutorial

How to Get Instagram Comments via API

Fetch the public comments of any Instagram post or reel with an API: pagination, replies, authors and a simple sentiment export, with working code.

Updated 31 October 2026 · 6 min read

Comments are where an audience tells you what it thinks. Reading them at scale powers social listening, giveaway tools, community research and sentiment analysis. The official Instagram API only returns comments for media your connected accounts own, so for other people’s public posts you need a public-data API such as the IGramAPI Comments API.

The endpoint

curl "https://api.igramapi.com/v1/media/Cx1AbCdEfGh/comments?limit=50" \
  -H "Authorization: Bearer $IGRAMAPI_KEY"

You can pass the shortcode (the part after /p/ or /reel/ in the URL) or a full URL. limit accepts 1 to 50 comments per page. Each page costs 2 credits.

A comment looks like this:

{
  "id": "18012345678901234",
  "text": "This is stunning, where was it taken?",
  "created_at": 1761901200,
  "like_count": 12,
  "reply_count": 2,
  "parent_comment_id": null,
  "author": { "id": "9876543210", "username": "traveler_amy", "is_verified": false }
}

Fetch all comments (Python)

import os
import requests

HEADERS = {"Authorization": f"Bearer {os.environ['IGRAMAPI_KEY']}"}

def comments(shortcode, max_pages=10):
    cursor, out = None, []
    for _ in range(max_pages):
        params = {"limit": 50}
        if cursor:
            params["cursor"] = cursor
        r = requests.get(
            f"https://api.igramapi.com/v1/media/{shortcode}/comments",
            headers=HEADERS, params=params, timeout=30,
        )
        r.raise_for_status()
        data = r.json()
        out.extend(data["items"])
        if not data["page"]["has_next_page"]:
            break
        cursor = data["page"]["end_cursor"]
    return out

rows = comments("Cx1AbCdEfGh")
print(len(rows), "comments")

The same in Node.js

async function comments(shortcode, maxPages = 10) {
  let cursor = null;
  const out = [];
  for (let i = 0; i < maxPages; i++) {
    const url = new URL(`https://api.igramapi.com/v1/media/${shortcode}/comments`);
    url.searchParams.set("limit", "50");
    if (cursor) url.searchParams.set("cursor", cursor);
    const response = await fetch(url, { headers: { Authorization: `Bearer ${process.env.IGRAMAPI_KEY}` } });
    const data = await response.json();
    out.push(...data.items);
    if (!data.page.has_next_page) break;
    cursor = data.page.end_cursor;
  }
  return out;
}

Always cap the number of pages. Each page costs credits, and a viral post can have thousands of comments.

How many comments can you get?

Instagram limits how deep the comment list of a very popular post can be read, so extremely long threads may not be fully retrievable. Compare len(rows) with total_comments in the response to see how much you captured, and record both in your report.

Rebuild reply threads

Replies carry a parent_comment_id. Group by it:

from collections import defaultdict

replies = defaultdict(list)
top_level = []
for c in rows:
    (replies[c["parent_comment_id"]] if c["parent_comment_id"] else top_level).append(c)

Export for analysis

import csv

with open("comments.csv", "w", newline="", encoding="utf-8") as f:
    writer = csv.writer(f)
    writer.writerow(["id", "created_at", "username", "likes", "text"])
    for c in rows:
        writer.writerow([c["id"], c["created_at"], c["author"]["username"], c["like_count"], c["text"]])

From there you can run a sentiment model, count mentions of your product or pick giveaway winners.

Giveaways and privacy

If you run giveaways, follow Instagram’s promotion rules. If you store commenter data, keep only what you need, tell people how you use it and delete it afterwards. Usernames and comments are personal data under many laws. Read our Acceptable Use Policy.

Find the post you need with the Posts API, or resolve any URL with the Post & Reel Data API. For the bigger picture, see brand and competitor monitoring.

More guides

Get your free API key

100 credits every month, no credit card. Make your first request in about two minutes.