# Instagram API post: free resources

From the APIWings guide [Instagram API post: requirements, limits and specs](https://apiwings.com/blog/instagram-api-post).
Code under the MIT License; data files under CC BY 4.0. Checked against Meta's official documentation on 26 November 2026.

| File | What it is |
|---|---|
| `instagram-post-preflight.mjs` | Checks a planned post (feed image, Reel, story or carousel) against Instagram's rules before you create a container. Node 18+, no dependencies. |
| `instagram_post_preflight.py` | The same checker in Python 3.9+, standard library only. Same results. |
| `instagram-publishing-rules.json` | Every rule the checkers use, with the Meta page it comes from. |
| `instagram-error-codes.json` | Publishing error subcodes and what to do with each one (fix the media, new container, retry, try tomorrow, reconnect, stop). |
| `example-posts.json` | The worked example: eight planned posts for a bakery account. |
| `preflight-test-cases.json` | 508 test cases with the expected result. |
| `test-preflight.mjs` / `test_preflight.py` | Run all test cases. Both print `508 of 508 cases pass`. |
| `make-test-cases.mjs` | Rebuilds the test cases (seeded, so the output is always the same). |
| `instagram-publish-example.mjs` | Publishes one image with the official API (Graph API v27.0): quota check, container, status check and publish, with timeouts, retries for temporary errors only, every container state handled and no double posts. The token never goes in a URL. Needs your own token. |
| `test-publish-example.mjs` | Runs the publishing script against a local mock of Meta's endpoints: 9 scenarios, prints `9 of 9 scenarios pass`. No real account is used. |
| `instagram-api-cheat-sheet.pdf` | One-page summary. |

## Try it

```
node instagram-post-preflight.mjs example-posts.json
python instagram_post_preflight.py example-posts.json
node test-preflight.mjs
python test_preflight.py
node test-publish-example.mjs
```

The preflight only reads metadata (format, bytes, width, height, duration, codecs, caption). Get it from your upload pipeline or from `ffprobe`; it never opens or downloads a file.

## What the preflight cannot check

Instagram still decides at publish time. The preflight does not know your daily quota (read `GET /<IG_ID>/content_publishing_limit`), whether your media URL is public, whether the account is restricted, or rules Meta does not document, such as size and duration limits for videos inside a carousel.

## Before production

`instagram-publish-example.mjs` was tested against a mock, not a live Instagram account. Before you run it for customers, add: state stored between runs (so a crash does not create a second post), token refresh, one queue per account, and an alert to a person for `stop_and_alert` errors (see `instagram-error-codes.json`).
