Original:🇺🇸 English
Translated
Instagram Graph API integration via curl. Use this skill to fetch and publish Instagram media.
14installs
Sourcevm0-ai/vm0-skills
Added on
NPX Install
npx skill4agent add vm0-ai/vm0-skills instagramTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Instagram API (Graph API)
Use the Instagram Graph API by directly executing commands to read and publish Instagram content.
curlOfficial docs:https://developers.facebook.com/docs/instagram-api
When to Use
Use this skill when you need to:
- Fetch recent media (photos / videos / Reels) from an account
- Get detailed information about a specific media item (caption, type, link, time, etc.)
- Search recent media by hashtag
- Publish image posts via API (with caption)
Prerequisites
- You must have an Instagram Business / Creator account linked to a Facebook Page
- Create an app in Facebook Developers and enable Instagram Basic Display / Instagram Graph API permissions
- Obtain:
- : a long-lived user access token
INSTAGRAM_ACCESS_TOKEN - : your Instagram Business account ID
INSTAGRAM_BUSINESS_ACCOUNT_ID
Set the environment variables, for example:
bash
export INSTAGRAM_ACCESS_TOKEN="EAAG..."
export INSTAGRAM_BUSINESS_ACCOUNT_ID="1784140xxxxxxx"These examples use Graph API version . You can replace this with the latest version if needed.
v21.0Required permissions (scopes)
Depending on which endpoints you use, make sure your app has requested and been approved for (at least):
instagram_basicpages_show_list- (for publishing media)
instagram_content_publish - and related permissions (for insights / some hashtag use cases)
instagram_manage_insights
Important: When usingin a command that pipes to another command, wrap the command containing$VARin$VAR. Due to a Claude Code bug, environment variables are silently cleared when pipes are used directly.bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"' | jq '.'
How to Use
All examples below assume you have already set:
bash
INSTAGRAM_ACCESS_TOKEN
INSTAGRAM_BUSINESS_ACCOUNT_ID1. Fetch recent media for the account
Fetch the most recent media (photos / videos / Reels) for the account:
bash
bash -c 'curl -s -X GET "https://graph.facebook.com/v21.0/${INSTAGRAM_BUSINESS_ACCOUNT_ID}/media?fields=id,caption,media_type,media_url,permalink,timestamp" --header "Authorization: Bearer ${INSTAGRAM_ACCESS_TOKEN}"'Notes:
- Each item in the returned JSON represents a media object
- Common fields:
- : media ID (used for details / insights later)
id - : caption text
caption - :
media_type/IMAGE/VIDEOCAROUSEL_ALBUM - : direct URL to the media
media_url - : Instagram permalink
permalink - : creation time
timestamp
2. Get details for a single media
If you already have a media , you can fetch more complete information. Replace with the field from the "Get User Media" response (section 1 above):
id<your-media-id>idbash
bash -c 'curl -s -X GET "https://graph.facebook.com/v21.0/<your-media-id>?fields=id,caption,media_type,media_url,permalink,thumbnail_url,timestamp,username" --header "Authorization: Bearer ${INSTAGRAM_ACCESS_TOKEN}"'3. Search media by hashtag
Note: hashtag search requires proper business use cases and permissions as defined by Facebook/Instagram. Refer to the official docs.
This usually involves two steps:
3.1 Get the hashtag ID
Replace with any hashtag name you want to search for (without the # symbol), e.g., "travel", "food", "photography":
<hashtag-name>bash
bash -c 'curl -s -X GET "https://graph.facebook.com/v21.0/ig_hashtag_search?user_id=${INSTAGRAM_BUSINESS_ACCOUNT_ID}&q=<hashtag-name>" --header "Authorization: Bearer ${INSTAGRAM_ACCESS_TOKEN}"'Note the field in the returned JSON for use in the next step.
id3.2 Fetch recent media for the hashtag
Replace with the field from the "Search Hashtag" response (section 3.1 above):
<hashtag-id>idbash
bash -c 'curl -s -X GET "https://graph.facebook.com/v21.0/<hashtag-id>/recent_media?user_id=${INSTAGRAM_BUSINESS_ACCOUNT_ID}&fields=id,caption,media_type,media_url,permalink,timestamp" --header "Authorization: Bearer ${INSTAGRAM_ACCESS_TOKEN}"'4. Publish an image post
Publishing an image post via the Graph API usually requires two steps:
- Create a media container
- Publish the container to the feed
4.1 Create a media container
Write the request data to :
/tmp/request.jsonjson
{
"image_url": "https://example.com/image.jpg",
"caption": "Hello from Instagram API 👋"
}Replace with any publicly accessible image URL and update the caption text as needed.
https://example.com/image.jpgbash
bash -c 'curl -s -X POST "https://graph.facebook.com/v21.0/${INSTAGRAM_BUSINESS_ACCOUNT_ID}/media" -H "Content-Type: application/json" -d @/tmp/request.json --header "Authorization: Bearer ${INSTAGRAM_ACCESS_TOKEN}"'The response will contain an (media container ID), for example:
idjson
{
"id": "1790xxxxxxxxxxxx"
}Note this ID for use in the next step.
4.2 Publish the media container to the feed
Write the request data to :
/tmp/request.jsonjson
{
"creation_id": "<your-creation-id>"
}Replace with the field from the "Create Media Container" response (section 4.1 above):
<your-creation-id>idbash
bash -c 'curl -s -X POST "https://graph.facebook.com/v21.0/${INSTAGRAM_BUSINESS_ACCOUNT_ID}/media_publish" -H "Content-Type: application/json" -d @/tmp/request.json --header "Authorization: Bearer ${INSTAGRAM_ACCESS_TOKEN}"'If successful, the response will contain the final media :
idjson
{
"id": "1791yyyyyyyyyyyy"
}You can then use the "Get details for a single media" command to fetch its .
permalink5. Common errors and troubleshooting
- Permissions / OAuth errors
- Typical error message:
(#10) Application does not have permission for this action - Check:
- Whether the app has been reviewed / approved
- Whether the required Instagram permissions are enabled
- Whether is a valid long-lived token
INSTAGRAM_ACCESS_TOKEN
- Unsupported account type
- Most Graph API features require Business / Creator accounts
- Make sure the Instagram account type is correct and linked to a Facebook Page
- Rate limits
- Too many requests in a short period may hit rate limits; add delays for bulk operations
Guidelines
- Do not log tokens: is sensitive; avoid printing it in logs or chat transcripts
INSTAGRAM_ACCESS_TOKEN - Validate curl commands in a test environment first: confirm flows before wiring them into automation / agents
- Keep API version up to date: periodically check Facebook docs and update the version in URLs to the latest
v21.0 - Use placeholder text for IDs: all examples use placeholder text like instead of shell variables in URLs to avoid dependencies and make examples self-contained
<your-media-id>