Fixing “Only photo or video can be accepted as media type” in the Instagram Graph API
Recently, while automating the process of publishing social media posts through the Instagram Graph API, I ran into a puzzling error:
“Only photo or video can be accepted as media type.”
At first I suspected the usual culprits — wrong image format, broken link, or file too large. But the real issue turned out to be something less obvious: my server’s robots.txt was blocking Meta’s crawlers. As soon as I fixed that, the API calls started working flawlessly.
Table of Contents
- Why this error appears
- The hidden culprit: robots.txt
- Server-side and Cloudflare rules
- How to check if robots.txt is blocking your images
- Fixing the issue
- Best practices to prevent future errors
- Conclusion
Why this error appears
If you’re working with the Instagram or Facebook Graph API and trying to create a media container with /{ig-user-id}/media, you may encounter the error:
“Only photo or video can be accepted as media type.”
At first glance, it usually means your image_url or video_url is invalid. Common causes include:
- The file is not public (requires login).
- The URL serves HTML instead of raw JPEG/MP4.
- The file is too large or in the wrong format (e.g. WebP, CMYK).
But there is a less obvious reason that many developers miss: restrictions in robots.txt.
The hidden culprit: robots.txt
Both Facebook and Instagram fetch media files using their own crawlers. If your server or CDN is configured to block crawlers via robots.txt, the request may be denied — even though the file is publicly accessible in your browser.
For example, a simple robots.txt on a staging server might look like this:
User-agent: *
Disallow: /
This effectively tells all crawlers, including Facebook’s, not to fetch any files. The Graph API respects this restriction and refuses to download your image, resulting in the error above.
Server-side and Cloudflare rules
Restrictions don’t always come from your web server. Content delivery networks like Cloudflare can apply “bot fight mode” or similar features that block automated requests — including those from Meta’s infrastructure.
| Layer | Example of block | Impact on Graph API |
|---|---|---|
| Server (nginx, Apache) | robots.txt with Disallow: / | Facebook crawler can’t fetch any media |
| CDN (Cloudflare, Akamai) | Firewall rules or Bot Fight mode | Requests from Facebook IPs get blocked |
| Application level | Password-protected staging server | Media URLs return login form instead of image |
How to check if robots.txt is blocking your images
- Open
https://yourdomain.com/robots.txtin a browser. - Look for rules that disallow
/or the path where your images are stored. - Test with cURL using Facebook’s crawler User-Agent: curl -I -A “facebookexternalhit/1.1” https://yourdomain.com/path/to/image.jpg
- If you see
200 OKandContent-Type: image/jpeg, the URL is fine. If you get blocked, your robots.txt or firewall is the culprit.
Fixing the issue
To fix the error, make sure your robots.txt allows Facebook and Instagram crawlers to access media files. Example of a permissive robots.txt:
User-agent: *
Allow: /insta/
Alternatively, remove the disallow rule completely if you’re ready for full indexation:
User-agent: *
Disallow:
On Cloudflare or similar CDNs, review firewall rules and ensure that requests from Facebook IP ranges are not blocked.
Best practices to prevent future errors
- Always host media on production-ready infrastructure, not on staging servers.
- Keep media URLs simple and direct (no redirects, no login pages).
- Ensure files are in sRGB JPEG (for images) or MP4 (for videos), under 8MB.
- Regularly check your robots.txt and firewall policies after deployments.
- If using Cloudflare, whitelist Facebook crawlers or disable aggressive bot filtering.
Conclusion
The error “Only photo or video can be accepted as media type” in the Instagram Graph API is not always about your file format. Sometimes it’s a simple configuration oversight in robots.txt or your CDN. By making sure that Facebook’s crawlers are allowed to fetch your content, you can avoid wasted hours of debugging and keep your publishing workflows running smoothly.
If you’re working with automation tools like n8n, Zapier, or custom scripts, it’s especially important to test your media URLs the same way Facebook does. A quick curl -I -A "facebookexternalhit/1.1" can save a lot of frustration.