# Instagram oEmbed API

> Get embed data for any public Instagram post or reel URL without a Meta app or access token: author, media id, shortcode, thumbnail and Instagram's embed HTML. Also tells what an instagram.com/s/ share link points to. 1 credit.

`GET /v1/instagram/oembed?url=` returns the embed data for a public Instagram post or reel: the author's username and id, the numeric media id and shortcode, a thumbnail and Instagram's own embed HTML. Instagram's official oEmbed endpoint needs a Meta developer app, app review and an access token; this route needs only your API key.

```
GET https://api.handlehaul.com/v1/instagram/oembed?url={instagram_url}
```

**Cost:** 1 credit per call read live. Answers are cached for 15 minutes; cache hits and failed calls are free.

## What it is for

- **Link previews and CMS embeds:** drop `html` into a page (it loads Instagram's own embed script), or build your own card from `title`, `author` and `thumbnail_url`.
- **Share links:** `instagram.com/s/…` links (how the app shares stories and highlights) carry no ids you can read. This route tells you the author and, for a highlight, its `highlight_id`, ready for the [Highlights API](/docs/instagram-highlights-api).
- **Owner of a post from its link**, without reading the whole post.

For a plain post or reel link, the free [URL resolver](/docs/instagram-url-resolver) already gives the shortcode and media id without any call to Instagram. Use this route when you also need the author, the thumbnail or the embed HTML, or when the link is a `/s/` share link.

## Parameters

| Parameter | In | Description |
|---|---|---|
| `url` | query | Required. An `instagram.com/p/…`, `/reel/…`, `/reels/…` or `/tv/…` link, or an `instagram.com/s/…` share link, URL-encoded. Tracking parameters are dropped before the lookup. |
| `fresh` | query | Optional. `true` bypasses the cache and is billed as a live call. |

## Response

Sandbox-key sample, live schema:

```json
{
  "data": {
    "type": "post",
    "media_id": "6856439962536382440",
    "shortcode": "F8m99Gmxg_o",
    "url": "https://www.instagram.com/p/F8m99Gmxg_o/",
    "title": "Sample caption olive",
    "author": {
      "id": "3505289814",
      "username": "cedar_nomad57",
      "url": "https://www.instagram.com/cedar_nomad57"
    },
    "highlight_id": null,
    "thumbnail_url": "https://scontent.cdninstagram.com/…/embed-6856439962536382440.jpg",
    "thumbnail_width": 640,
    "thumbnail_height": 800,
    "width": 658,
    "html": "<blockquote class=\"instagram-media\" data-instgrm-permalink=\"https://www.instagram.com/p/F8m99Gmxg_o/\" data-instgrm-version=\"14\"></blockquote><script async src=\"//www.instagram.com/embed.js\"></script>"
  },
  "meta": {
    "request_id": "req_…",
    "cached": false,
    "cache_age_seconds": 0,
    "credits_charged": 1,
    "credits_remaining": 26943
  }
}
```

| Field | Meaning |
|---|---|
| `type` | `post` for a post or reel link, `share_link` for an `/s/` link |
| `media_id`, `shortcode`, `url` | The post, when the link points to one |
| `author` | `id`, `username` and profile `url` of the account that posted it |
| `highlight_id` | Set when a share link points to a story highlight |
| `thumbnail_url`, `thumbnail_width`, `thumbnail_height` | Instagram's preview image |
| `html` | Instagram's embed markup: a blockquote plus `instagram.com/embed.js` |

## Examples

```bash
curl "https://api.handlehaul.com/v1/instagram/oembed?url=https%3A%2F%2Fwww.instagram.com%2Fp%2FDCSf3TJ3gB7%2F" -H "X-Api-Key: $HANDLEHAUL_API_KEY"
```

```javascript
const url = new URL("https://api.handlehaul.com/v1/instagram/oembed");
url.searchParams.set("url", "https://www.instagram.com/p/DCSf3TJ3gB7/");
const res = await fetch(url, { headers: { "X-Api-Key": process.env.HANDLEHAUL_API_KEY } });
const { data } = await res.json();
console.log(data.author.username, data.media_id, data.thumbnail_url);
```

```python
import os, requests

r = requests.get(
    "https://api.handlehaul.com/v1/instagram/oembed",
    params={"url": "https://www.instagram.com/p/DCSf3TJ3gB7/"},
    headers={"X-Api-Key": os.environ["HANDLEHAUL_API_KEY"]},
)
embed = r.json()["data"]
print(embed["author"]["username"], embed["shortcode"])
```

```php
$ch = curl_init("https://api.handlehaul.com/v1/instagram/oembed?url=https%3A%2F%2Fwww.instagram.com%2Fp%2FDCSf3TJ3gB7%2F");
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/instagram/oembed?url=https%3A%2F%2Fwww.instagram.com%2Fp%2FDCSf3TJ3gB7%2F", 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"])
```

## Errors

| Status | Code | When |
|---|---|---|
| 400 | `invalid_request` | `url` is missing or is not an instagram.com post, reel or share link |
| 403 | `private_account` | The post belongs to a private account (not billed) |
| 404 | `user_not_found` | No such post, or the link has expired (not billed) |

## FAQ

### Can I use Instagram oEmbed without a Facebook app?
Yes. Send the post URL to `/v1/instagram/oembed`; you get the same kind of data Instagram's own oEmbed returns, with only a HandleHaul API key.

### Does the embed HTML work on my site?
It is Instagram's own markup and script, so it renders the way Instagram's embeds do. Posts from private accounts cannot be embedded.

### How do I find what an instagram.com/s/ link points to?
Pass it as `url`. The answer names the author and, for a highlight, the `highlight_id`.
