# Instagram Posts API

> Get a public Instagram account's recent posts as JSON: shortcode, URL, date, type, caption, and like, comment and view counts, with cursor pagination. 1 credit per page.

**Get a public account's recent posts**, newest first: link, date, type (photo, video or carousel), caption, and like, comment and view counts.

```
GET https://api.handlehaul.com/v1/users/{user}/posts
```

**Cost:** 1 credit per page (free from cache). About 12 posts a page. Naming the account by a username we have to look up adds 1 credit; send the numeric id to skip it ([details](/pricing#usernames-and-ids)).

## Parameters

| Parameter | In | Description |
|---|---|---|
| `user` | path | Numeric user id (cheapest) or username. A username we have to look up costs 1 extra credit ([why](/docs/pricing#usernames-and-ids)). All digits = an id; write `@12345` for an all-digit username. |
| `by` | query | Optional. `username` or `id`: says which one `user` is, instead of guessing from the digits. |
| `cursor` | query | `pagination.next_cursor` from the previous page. |
| `fresh` | query | `true` skips the cache. |

## Response

```json
{
  "data": [
    {
      "id": "3500000000000000001",
      "shortcode": "C9xYzAbCdEf",
      "url": "https://www.instagram.com/p/C9xYzAbCdEf/",
      "taken_at": "2026-11-27T18:04:11.000Z",
      "media_type": "carousel",
      "caption": "Weekend dump",
      "counts": { "likes": 1204, "comments": 37, "views": null },
      "thumbnail_url": "https://scontent.cdninstagram.com/…"
    }
  ],
  "pagination": { "next_cursor": null, "has_more": false, "page_size": 12 },
  "meta": { "request_id": "req_…", "cached": false, "cache_age_seconds": 0, "credits_charged": 1, "credits_remaining": 26945.5 }
}
```

`counts.views` is set for videos and `null` otherwise. A count Instagram hides comes back as `null`.

## Examples

```bash
curl "https://api.handlehaul.com/v1/users/natgeo/posts" -H "X-Api-Key: $HANDLEHAUL_API_KEY"
```

```python
import os, requests
posts = requests.get("https://api.handlehaul.com/v1/users/natgeo/posts",
                     headers={"X-Api-Key": os.environ["HANDLEHAUL_API_KEY"]}, timeout=30).json()["data"]
avg_likes = sum(p["counts"]["likes"] or 0 for p in posts) / max(len(posts), 1)
```

```javascript
const { data: posts } = await (await fetch("https://api.handlehaul.com/v1/users/natgeo/posts", {
  headers: { "X-Api-Key": process.env.HANDLEHAUL_API_KEY },
})).json();
```

```php
$ch = curl_init("https://api.handlehaul.com/v1/users/natgeo/posts");
curl_setopt_array($ch, [
    CURLOPT_HTTPHEADER => ["X-Api-Key: " . getenv("HANDLEHAUL_API_KEY")],
    CURLOPT_RETURNTRANSFER => true,
]);
$body = json_decode(curl_exec($ch), true);
print_r($body["data"]);
```

```go
req, _ := http.NewRequest("GET", "https://api.handlehaul.com/v1/users/natgeo/posts", nil)
req.Header.Set("X-Api-Key", os.Getenv("HANDLEHAUL_API_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil {
    log.Fatal(err)
}
defer res.Body.Close()
var body map[string]any
json.NewDecoder(res.Body).Decode(&body)
fmt.Println(body["data"])
```

## FAQ

### How do I get an Instagram account's latest posts with an API?
Call `GET /v1/users/{username}/posts`. Posts come newest first with URL, date, caption and engagement counts.
