Modules@robinpath/instagram
instagram

@robinpath/instagram

0.1.1Node.jsPublic

Instagram module for RobinPath.

Instagram

Instagram module for RobinPath.

Package: @robinpath/instagram | Category: Social Media | Type: Integration

Authentication

instagram.setToken "EAAG..."

Call this once at the start of your script before using any other function. Credentials persist for the duration of the script execution.

Use Cases

Use the instagram module when you need to:

  • Get authenticated user's Instagram profile (id, username, biography, followers, media count, etc.) -- Use instagram.getProfile to perform this operation
  • Get details of a specific media item by ID -- Use instagram.getMedia to perform this operation
  • List the authenticated user's media posts with pagination -- Use instagram.listMedia to perform this operation
  • Create a media container for an image post (returns container ID for publishing) -- Use instagram.createMediaContainer to perform this operation
  • Create a media container for a video or Reel post -- Use instagram.createVideoContainer to perform this operation

Quick Reference

FunctionDescriptionReturns
setTokenStore a long-lived Instagram access token for API calls{ok, accountId}
setBusinessAccountStore access token and IG Business Account ID for full API access{ok, accountId, igBusinessAccountId}
getProfileGet authenticated user's Instagram profile (id, username, biography, followers, media count, etc.){id, name, username, biography, followers_count, follows_count, media_count, ...}
getMediaGet details of a specific media item by ID{id, caption, media_type, media_url, timestamp, permalink, like_count, comments_count, ...}
listMediaList the authenticated user's media posts with pagination{data: [...media], paging: {cursors, next, previous}}
createMediaContainerCreate a media container for an image post (returns container ID for publishing){id} - container ID for use with publishMedia
createVideoContainerCreate a media container for a video or Reel post{id} - container ID for use with publishMedia
createCarouselContainerCreate a carousel container from multiple child container IDs{id} - carousel container ID for use with publishMedia
publishMediaPublish a previously created media container (image, video, or carousel){id} - published media ID
getMediaInsightsGet insights/analytics for a specific media item{data: [{name, period, values, title, description, id}]}
getAccountInsightsGet account-level insights (impressions, reach, follower_count, etc.){data: [{name, period, values, title, description}]}
getCommentsList comments on a media post{data: [{id, text, timestamp, username, like_count}], paging}
replyToCommentReply to a specific comment on a media post{id} - reply comment ID
deleteCommentDelete or hide a comment by ID{ok, commentId}
getStoriesGet the authenticated user's currently active stories{data: [{id, media_type, media_url, timestamp, permalink}]}
getHashtagSearch for a hashtag ID by name{data: [{id}]}
getHashtagMediaGet top or recent media for a hashtag{data: [...media], paging}
getMentionsGet media posts where the authenticated user is tagged/mentioned{data: [...media], paging}
sendMessageSend a direct message to a user via Instagram Messaging API{recipient_id, message_id}
getConversationsList DM conversations for the authenticated account{data: [{id, updated_time, participants, messages}], paging}
getMessagesGet messages within a specific DM conversation{data: [{id, message, from, to, created_time}], paging}

Functions

setToken

Store a long-lived Instagram access token for API calls

Module: instagram | Returns: object -- {ok, accountId}

instagram.setToken "EAAG..."
ParameterTypeRequiredDescription
accessTokenstringYesLong-lived access token from Meta/Facebook

setBusinessAccount

Store access token and IG Business Account ID for full API access

Module: instagram | Returns: object -- {ok, accountId, igBusinessAccountId}

instagram.setBusinessAccount "EAAG..." "17841400123456"
ParameterTypeRequiredDescription
accessTokenstringYesLong-lived access token from Meta/Facebook
igBusinessAccountIdstringYesInstagram Business Account ID (numeric)

getProfile

Get authenticated user's Instagram profile (id, username, biography, followers, media count, etc.)

Module: instagram | Returns: object -- {id, name, username, biography, followers_count, follows_count, media_count, ...}

instagram.getProfile
ParameterTypeRequiredDescription
optionsobjectNo{fields?: string} - comma-separated fields to retrieve

getMedia

Get details of a specific media item by ID

Module: instagram | Returns: object -- {id, caption, media_type, media_url, timestamp, permalink, like_count, comments_count, ...}

instagram.getMedia "17895695668004550"
ParameterTypeRequiredDescription
mediaIdstringYesMedia ID to retrieve
fieldsstringNoComma-separated fields (default: id,caption,media_type,media_url,timestamp,permalink,like_count,comments_count)

listMedia

List the authenticated user's media posts with pagination

Module: instagram | Returns: object -- {data: [...media], paging: {cursors, next, previous}}

instagram.listMedia {"limit": 10}
ParameterTypeRequiredDescription
optionsobjectNo{limit?, after?, before?, fields?}

createMediaContainer

Create a media container for an image post (returns container ID for publishing)

Module: instagram | Returns: object -- {id} - container ID for use with publishMedia

instagram.createMediaContainer "https://example.com/photo.jpg" "Beautiful sunset! #nature"
ParameterTypeRequiredDescription
imageUrlstringYesPublic URL of the image to post
captionstringNoPost caption text
optionsobjectNo{locationId?, userTags?, isCarouselItem?}

createVideoContainer

Create a media container for a video or Reel post

Module: instagram | Returns: object -- {id} - container ID for use with publishMedia

instagram.createVideoContainer "https://example.com/video.mp4" "Check this out!" {"mediaType": "REELS"}
ParameterTypeRequiredDescription
videoUrlstringYesPublic URL of the video
captionstringNoPost caption text
optionsobjectNo{mediaType?: 'REELS'

createCarouselContainer

Create a carousel container from multiple child container IDs

Module: instagram | Returns: object -- {id} - carousel container ID for use with publishMedia

instagram.createCarouselContainer ["17889615691123456", "17889615691123457"] "Photo dump!"
ParameterTypeRequiredDescription
childrenarrayYesArray of child container IDs (minimum 2)
captionstringNoCarousel caption text

publishMedia

Publish a previously created media container (image, video, or carousel)

Module: instagram | Returns: object -- {id} - published media ID

instagram.publishMedia "17889615691123456"
ParameterTypeRequiredDescription
containerIdstringYesContainer ID from createMediaContainer, createVideoContainer, or createCarouselContainer

getMediaInsights

Get insights/analytics for a specific media item

Module: instagram | Returns: object -- {data: [{name, period, values, title, description, id}]}

instagram.getMediaInsights "17895695668004550" "impressions,reach,engagement,saved"
ParameterTypeRequiredDescription
mediaIdstringYesMedia ID to get insights for
metricsstringNoComma-separated metrics (default: impressions,reach,engagement,saved)

getAccountInsights

Get account-level insights (impressions, reach, follower_count, etc.)

Module: instagram | Returns: object -- {data: [{name, period, values, title, description}]}

instagram.getAccountInsights "impressions,reach,follower_count" "day"
ParameterTypeRequiredDescription
metricsstringYesComma-separated metrics (e.g. impressions,reach,follower_count)
periodstringYesTime period: day, week, days_28, month, lifetime
optionsobjectNo{since?: unix_timestamp, until?: unix_timestamp}

getComments

List comments on a media post

Module: instagram | Returns: object -- {data: [{id, text, timestamp, username, like_count}], paging}

instagram.getComments "17895695668004550" {"limit": 25}
ParameterTypeRequiredDescription
mediaIdstringYesMedia ID to list comments for
optionsobjectNo{limit?, after?, fields?}

replyToComment

Reply to a specific comment on a media post

Module: instagram | Returns: object -- {id} - reply comment ID

instagram.replyToComment "17858893269123456" "Thank you!"
ParameterTypeRequiredDescription
commentIdstringYesComment ID to reply to
messagestringYesReply text

deleteComment

Delete or hide a comment by ID

Module: instagram | Returns: object -- {ok, commentId}

instagram.deleteComment "17858893269123456"
ParameterTypeRequiredDescription
commentIdstringYesComment ID to delete

getStories

Get the authenticated user's currently active stories

Module: instagram | Returns: object -- {data: [{id, media_type, media_url, timestamp, permalink}]}

instagram.getStories
ParameterTypeRequiredDescription
optionsobjectNo{fields?: string}

getHashtag

Search for a hashtag ID by name

Module: instagram | Returns: object -- {data: [{id}]}

instagram.getHashtag "travel"
ParameterTypeRequiredDescription
hashtagNamestringYesHashtag name without # (e.g. 'travel')

getHashtagMedia

Get top or recent media for a hashtag

Module: instagram | Returns: object -- {data: [...media], paging}

instagram.getHashtagMedia "17843853986012965" "top_media" {"limit": 20}
ParameterTypeRequiredDescription
hashtagIdstringYesHashtag ID from getHashtag
typestringNo'top_media' or 'recent_media' (default: top_media)
optionsobjectNo{limit?, after?, fields?}

getMentions

Get media posts where the authenticated user is tagged/mentioned

Module: instagram | Returns: object -- {data: [...media], paging}

instagram.getMentions {"limit": 10}
ParameterTypeRequiredDescription
optionsobjectNo{limit?, after?, fields?}

sendMessage

Send a direct message to a user via Instagram Messaging API

Module: instagram | Returns: object -- {recipient_id, message_id}

instagram.sendMessage "17841400123456" "Hello from RobinPath!"
ParameterTypeRequiredDescription
recipientIdstringYesInstagram-scoped ID of the recipient
messagestringYesMessage text to send

getConversations

List DM conversations for the authenticated account

Module: instagram | Returns: object -- {data: [{id, updated_time, participants, messages}], paging}

instagram.getConversations {"limit": 10}
ParameterTypeRequiredDescription
optionsobjectNo{limit?, after?, fields?}

getMessages

Get messages within a specific DM conversation

Module: instagram | Returns: object -- {data: [{id, message, from, to, created_time}], paging}

instagram.getMessages "t_1234567890" {"limit": 20}
ParameterTypeRequiredDescription
conversationIdstringYesConversation ID from getConversations
optionsobjectNo{limit?, after?, fields?}

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Access token is required.Check the error message for details
IG Business Account ID is required.Check the error message for details
IG Business Account ID is required. Call instagram.setBusinessAccount first.Check the error message for details
Media ID is required.Check the error message for details
Image URL is required.Check the error message for details
Video URL is required.Check the error message for details
At least 2 child container IDs are required for a carousel.Check the error message for details
Container ID is required.Check the error message for details
@desc "Get profile and validate result"
do
  set $result as instagram.getProfile
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate Profile

Retrieve all items and loop through them.

@desc "Setup authentication"
do
  instagram.setToken $token
enddo

@desc "Get profile and iterate results"
do
  set $result as instagram.getProfile
  each $item in $result
    print $item
  end
enddo

2. Create a new item with createMediaContainer

Create a new resource and capture the result.

@desc "Setup authentication"
do
  instagram.setToken $token
enddo

@desc "Create media container"
do
  set $result as instagram.createMediaContainer "https://example.com/photo.jpg" "Beautiful sunset! #nature"
  print "Created: " + $result
enddo

3. Check before creating

List existing items and only create if needed.

@desc "Setup authentication"
do
  instagram.setToken $token
enddo

@desc "Get profile and create media container"
do
  set $existing as instagram.getProfile
  if $existing == null
    instagram.createMediaContainer "https://example.com/photo.jpg" "Beautiful sunset! #nature"
    print "Item created"
  else
    print "Item already exists"
  end
enddo

4. Multi-step Instagram workflow

Chain multiple instagram operations together.

@desc "Setup authentication"
do
  instagram.setToken $token
enddo

@desc "Get profile, get media, and more"
do
  set $r_getProfile as instagram.getProfile
  set $r_getMedia as instagram.getMedia "17895695668004550"
  set $r_listMedia as instagram.listMedia {"limit": 10}
  print "All operations complete"
enddo

5. Safe getProfile with validation

Check results before proceeding.

@desc "Setup authentication"
do
  instagram.setToken $token
enddo

@desc "Get profile and validate result"
do
  set $result as instagram.getProfile
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • facebook -- Facebook module for complementary functionality
  • twitter -- Twitter/X module for complementary functionality
  • linkedin -- LinkedIn module for complementary functionality
  • tiktok -- TikTok module for complementary functionality
  • pinterest -- Pinterest module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/instagram

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size9.1 KB
Versions1
Weekly Downloads26
Total Downloads26
Stars0
Last Publish1 months ago
Created1 months ago

Category

marketing