# Instagram Profile API

> Get a public Instagram profile as JSON with one call: bio, website, category, verified status, profile picture, and follower, following and post counts. 1 credit per successful call.

**Get a public Instagram profile as JSON**: bio, website, category, verified status, HD profile picture, and follower, following and post counts.

```
GET https://api.handlehaul.com/v1/users/by-username/{username}
GET https://api.handlehaul.com/v1/users/by-id/{id}
GET https://api.handlehaul.com/v1/users/{user}            # username or id
```

All three return the same profile. Use **by-id** when you stored ids (ids survive renames), **by-username** when you have a handle, and `{user}` when you accept either.

**Cost:** 1 credit per successful call (free from cache). Profiles are cached for 60 seconds.

## Parameters

| Parameter | In | Description |
|---|---|---|
| `username` | path | by-username: an Instagram username (`natgeo`), always read as a username. |
| `id` | path | by-id: a numeric Instagram user id (`787132`). |
| `user` | path | `{user}` route: a username or a numeric id. All digits = an id; write `@12345` (or add `by=username`) for an all-digit username. No lookup credit here: the lookup is the call. |
| `fresh` | query | `true` skips the cache. Same as the header `Cache-Control: no-cache`. |

## Response

```json
{
  "data": {
    "id": "787132",
    "username": "natgeo",
    "full_name": "National Geographic",
    "is_private": false,
    "is_verified": true,
    "profile_pic_url": "https://scontent.cdninstagram.com/…",
    "biography": "Experience the world through the eyes of our photographers.",
    "external_url": "https://www.nationalgeographic.com",
    "category": "Media/news company",
    "is_business": true,
    "profile_pic_url_hd": "https://scontent.cdninstagram.com/…",
    "counts": { "followers": 280000000, "following": 160, "posts": 30500 }
  },
  "meta": { "request_id": "req_Zt0q…", "cached": true, "cache_age_seconds": 141, "credits_charged": 0.5, "credits_remaining": 26948.5 }
}
```

Private accounts return their public profile fields with `is_private: true`; their lists and posts are not available.

## Examples

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

```python
import os, requests
p = requests.get("https://api.handlehaul.com/v1/users/natgeo",
                 headers={"X-Api-Key": os.environ["HANDLEHAUL_API_KEY"]}, timeout=30).json()["data"]
print(p["counts"]["followers"])
```

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

```php
$ch = curl_init("https://api.handlehaul.com/v1/users/by-username/natgeo");
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/by-username/natgeo", 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 someone's Instagram follower count with an API?
Call `GET /v1/users/by-username/{username}`. The follower count is in `data.counts.followers`, next to `following` and `posts`.

### How fresh is the profile data?
Answers are cached for 60 seconds (a cached answer is free) and `meta.cache_age_seconds` tells you the age. Pass `fresh=true` for a live fetch.

### Can I get an Instagram profile by user id?
Yes: `GET /v1/users/by-id/{id}` returns the same profile for a numeric user id.
