# Export an Instagram following list to CSV

> To export who a public Instagram account follows to CSV, page through GET /v1/users/{user}/following until next_cursor is null and write one row per account. Rows are newest first, so the file is in follow order. Code and costs.

**Short answer:** to export the accounts a public Instagram profile follows, call `GET /v1/users/{user}/following`, write each row of `data` to a CSV file, and repeat with `?cursor=` set to `pagination.next_cursor` until it is `null`. The Klupt API returns the list **newest first**, so row 1 of your CSV is the account they followed most recently.

> **Definition:** a *following list export* is a file with one line per account a profile follows. Each line from the Klupt API carries `position` (1 = most recent follow), `id`, `username`, `full_name`, `is_verified`, `is_private` and `profile_pic_url`.

## What an export costs

Each page holds about 200 accounts and costs 2 credits. Instagram lets an account follow at most 7,500 others, so even the largest export is a few dozen pages:

| Accounts followed | Pages (about 200 each) | Credits | Cost at $2.00 per 1,000 credits |
|---|---|---|---|
| 500 | 3 | 6 | $0.01 |
| 2,000 | 10 | 20 | $0.04 |
| 7,500 | 38 | 76 | $0.15 |

Failed calls are not billed. Repeating an export within 15 minutes reads later pages from cache, which costs nothing.

## One page with curl and jq

```sh
curl "https://api.klupt.io/v1/users/natgeo/following" \
  -H "X-Api-Key: $KLUPT_API_KEY" \
  | jq -r '.data[] | [.position, .id, .username, .full_name, .is_verified] | @csv' > following.csv
```

## The whole list in Python

```python
import csv, os, requests

API = "https://api.klupt.io/v1"
H = {"X-Api-Key": os.environ["KLUPT_API_KEY"]}
FIELDS = ["position", "id", "username", "full_name", "is_verified", "is_private", "profile_pic_url"]

def export_following(user, path):
    cursor = None
    with open(path, "w", newline="", encoding="utf-8") as f:
        out = csv.DictWriter(f, fieldnames=FIELDS, extrasaction="ignore")
        out.writeheader()
        while True:
            params = {"cursor": cursor} if cursor else {}
            r = requests.get(f"{API}/users/{user}/following", headers=H, params=params, timeout=60)
            r.raise_for_status()
            body = r.json()
            out.writerows(body["data"])
            cursor = body["pagination"]["next_cursor"]
            if not cursor:
                break

export_following("natgeo", "natgeo-following.csv")
```

## The whole list in Node.js

```javascript
import { writeFile } from "node:fs/promises";

const API = "https://api.klupt.io/v1";
const FIELDS = ["position", "id", "username", "full_name", "is_verified", "is_private", "profile_pic_url"];
const cell = (v) => `"${String(v ?? "").replace(/"/g, '""')}"`;

async function exportFollowing(user, file) {
  const lines = [FIELDS.join(",")];
  let cursor = null;
  do {
    const qs = cursor ? `?cursor=${encodeURIComponent(cursor)}` : "";
    const res = await fetch(`${API}/users/${user}/following${qs}`, {
      headers: { "X-Api-Key": process.env.KLUPT_API_KEY },
    });
    const body = await res.json();
    if (!res.ok) throw new Error(`${body.error.code}: ${body.error.message}`);
    for (const row of body.data) lines.push(FIELDS.map((k) => cell(row[k])).join(","));
    cursor = body.pagination.next_cursor;
  } while (cursor);
  await writeFile(file, lines.join("\n") + "\n");
}

await exportFollowing("natgeo", "natgeo-following.csv");
```

Pages are read one after another, because each page needs the cursor from the one before. If you hit `429 rate_limited`, wait for the `Retry-After` header and repeat the same page ([Rate limits](/docs/rate-limits)).

## Exporting followers instead

Swap `following` for `followers` in the URL. Follower pages hold 25 accounts for 1 credit each, newest first, so a full follower export of a big account takes many pages: read only as deep as you need ([Followers API](/docs/instagram-followers-api)).

## Things to know

- **Public accounts only.** A private account answers `403 private_account` (not billed).
- **Hidden lists:** some public accounts hide who they follow. You get an empty page with `meta.list_hidden: true`.
- **No follow dates:** Instagram does not publish them. The `position` column is the order; to date new follows, export on a schedule and compare ([Detect new follows](/docs/detect-new-instagram-followers-api)).
- **Spreadsheet tip:** keep the `id` column as text, or long ids lose digits in Excel and Google Sheets.

## FAQ

### How do I export someone's Instagram following list to CSV?
Page through GET /v1/users/{user}/following on the Klupt API until pagination.next_cursor is null, and write each row (position, id, username, full_name, is_verified) to a CSV file. The rows are newest first, so the file is in follow order.

### How much does it cost to export a following list?
About 200 accounts per page at 2 credits a page. The largest possible list, 7,500 accounts, is 38 pages. Failed calls are not billed.

### Is the exported list in chronological order?
Yes. The Klupt API returns the following list newest first and says so in meta.order, so position 1 is the most recent follow. Instagram does not publish follow dates, so the file has the order but no dates.

### Can I export an Instagram followers list too?
Yes, from GET /v1/users/{user}/followers, 25 accounts per page, newest first, 1 credit a page.

### Can I export the following list of a private account?
No. The Klupt API covers public accounts only, and a private account answers private_account, which is not billed.
