# Call Instagram post data from a Python script with requests

From Python, the call is a single requests.post to https://api.routergrowth.com/v1/run with your key in the Authorization header and a body naming social.posts, the platform and the handle. The JSON that comes back holds the posts, the run_id and what was charged, ready for a DataFrame or a CSV.

HTML page: https://www.routergrowth.com/tools/instagram/api-python
Part of: [Instagram tools](https://www.routergrowth.com/tools/instagram.md)

## The call

[`social.posts`](https://www.routergrowth.com/catalog/social.posts): Recent public posts for a social handle.

Price on this network: $0.004025 per post, $0.002 minimum a call. The exact quote is shown before every run.

## What a real run returned

Run on 2026-10-19: 5 records in 15.2 s for $0.020125. Personal fields are masked. Five posts from the public Our Place account, as the script would receive them: product launches with like, reply and view counts.

| created_at | text | likes | replies | views | is_video |
|---|---|---|---|---|---|
| 2026-06-09 | Meet Vanilla Bean, our newest limited-edition flavor of ceramic cookware. A warm, never-boring neutral, it’s a classic for a reason. Don’t… | 1561 | 289 | None | False |
| 2025-09-30 | ✨ Meet the newest member of the Wonder Oven family: the Pro ✨All the wonder you love - air frying, steam infusion, non-toxic materials - no… | 5820 | 1708 | None | False |
| 2026-04-13 | Something’s in the air… a new way to cook your grains. Launching tomorrow, 4/14. | 3289 | 730 | 85297 | True |

## How to do it

1. **Put the key in the environment.** Store ROUTERGROWTH_API_KEY as an environment variable and send it as Authorization: Bearer. No Meta app, no OAuth flow.
2. **Post the run.** requests.post to /v1/run with a JSON body: capability social.posts, input with platform, handle and limit, and routing.max_cost as a ceiling.
3. **Read result.posts.** Loop over response.json()['result']['posts']. Each item has url, text, created_at and engagement with likes, replies and views.
4. **Send an Idempotency-Key.** Add the header on retries so a script that runs twice does not pay twice for the same request.

## Ask it like this

- Write a Python script that pulls the last 20 Instagram posts for each handle in brands.csv and saves them to posts.csv. (`social.posts`)
- Extend the script: for every post with more than 500 replies, fetch the comments and count the questions. (`social.posts`, `social.comments`)

## Connect

MCP server: `https://api.routergrowth.com/mcp`

```bash
claude mcp add --transport http routergrowth https://api.routergrowth.com/mcp
```

```bash
npm install -g routergrowth && routergrowth setup
routergrowth run -c social.posts -i '{"platform": "instagram", "handle": "ourplace", "limit": 5}'
```

```bash
curl -X POST https://api.routergrowth.com/v1/run \
  -H "Authorization: Bearer $ROUTERGROWTH_API_KEY" \
  -d '{"capability": "social.posts", "input": {"platform": "instagram", "handle": "ourplace", "limit": 5}}'
```

## Worth knowing

- **One endpoint for every network.** The same /v1/run call reads TikTok, LinkedIn or YouTube posts by changing platform. The record shape stays the same.
- **Synchronous by default.** A short run returns its result in the response. Longer runs return a run_id to poll at /v1/runs/<id>.
- **Not the Graph API.** There is no Instagram SDK to install and no Meta token. RouterGrowth reads public posts independently of Meta.

## Questions

### Is there a Python SDK?

Not needed. The REST call works with requests or httpx, and the CLI covers shell scripts.

### What does the script get back?

A JSON object with run_id, status, billing and result.posts. Each post has id, url, text, created_at, author, engagement and is_video.

### How do I keep a script from overspending?

Put routing.max_cost in each request. A run whose quote is above it is refused before it bills.

### Can I run it on a schedule?

Yes. Cron or any scheduler can call the same endpoint; for repeated reads, watch returns only what changed since the last call.

## Related

- [Scrape the posts under an Instagram hashtag without running a scraper](https://www.routergrowth.com/tools/instagram/scraper.md)
- [Scrape a brand's Instagram profile into one clean record](https://www.routergrowth.com/tools/instagram/profile-scraper.md)
- [Scrape a brand's Instagram posts with captions and engagement, no setup](https://www.routergrowth.com/tools/instagram/posts-scraper.md)
- [Scrape the comments under a brand's Instagram post](https://www.routergrowth.com/tools/instagram/comment-scraper.md)
- [What reading Instagram posts costs: a quote before, a charge per post after](https://www.routergrowth.com/tools/instagram/api-costs.md)
- [Read any public Instagram brand feed through one REST or MCP call](https://www.routergrowth.com/tools/instagram/api.md)
