productivity
Instagram Lua API for KosmoKrator Agents
Agent-facing Lua documentation and function reference for the Instagram KosmoKrator integration.Lua Namespace
Agents call this integration through app.integrations.instagram.*.
Use lua_read_doc("integrations.instagram") inside KosmoKrator to discover the same reference at runtime.
Call Lua from the Headless CLI
Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic
Instagram workflow without starting an interactive agent session.
kosmo integrations:lua --eval 'dump(app.integrations.instagram.list_media({limit = 1, after = "example_after", before = "example_before", fields = "example_fields"}))' --json kosmo integrations:lua --eval 'print(docs.read("instagram"))' --json
kosmo integrations:lua --eval 'print(docs.read("instagram.list_media"))' --json Workflow file
Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.
local instagram = app.integrations.instagram
local result = instagram.list_media({limit = 1, after = "example_after", before = "example_before", fields = "example_fields"})
dump(result) kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json integrations:lua exposes app.integrations.instagram, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.instagram.default.* or app.integrations.instagram.work.* when you configured named credential accounts.
MCP-only Lua
If the script only needs configured MCP servers and does not need Instagram, use the narrower mcp:lua command.
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json Agent-Facing Lua Docs
This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.
Instagram — Lua API Reference
list_media
List media published by the authenticated Instagram user.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
limit | integer | no | Number of media items to return per page |
after | string | no | Pagination cursor — return items after this cursor |
before | string | no | Pagination cursor — return items before this cursor |
fields | string | no | Comma-separated fields to return |
Example
local result = app.integrations.instagram.list_media({
limit = 25
})
for _, media in ipairs(result.data) do
print(media.id .. ": " .. (media.caption or "No caption") .. " (" .. media.media_type .. ")")
end
-- Use paging cursor for next page
if result.paging and result.paging.cursors then
local next = app.integrations.instagram.list_media({
limit = 25,
after = result.paging.cursors.after
})
end
get_media
Get details of a specific Instagram media item by ID.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
mediaId | string | yes | The media ID to retrieve |
fields | string | no | Comma-separated fields to return |
Example
local result = app.integrations.instagram.get_media({
mediaId = "17895695668004550"
})
print(result.caption)
print(result.media_type)
print(result.media_url)
print("Likes: " .. (result.like_count or 0))
create_media
Publish a new media item (photo or video) to Instagram.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
imageUrl | string | yes | URL of the image or video to publish |
caption | string | no | Caption text for the media post |
mediaType | string | no | Type of media: “IMAGE”, “VIDEO”, or “CAROUSEL” |
publish | boolean | no | Publish immediately (default true). Set false to create container only |
Example
local result = app.integrations.instagram.create_media({
imageUrl = "https://example.com/photo.jpg",
caption = "Check out our latest product launch! 🚀"
})
print("Published media ID: " .. result.id)
list_comments
List comments on a specific Instagram media item.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
mediaId | string | yes | The media ID to list comments for |
limit | integer | no | Number of comments to return per page |
after | string | no | Pagination cursor — return comments after this cursor |
Example
local result = app.integrations.instagram.list_comments({
mediaId = "17895695668004550",
limit = 20
})
for _, comment in ipairs(result.data) do
print(comment.username .. ": " .. comment.text)
end
get_comment
Get details of a specific Instagram comment by ID.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
commentId | string | yes | The comment ID to retrieve |
Example
local result = app.integrations.instagram.get_comment({
commentId = "17853788044894720"
})
print(result.username .. ": " .. result.text)
print("Likes: " .. (result.like_count or 0))
list_insights
Get account-level insights and performance metrics for the authenticated Instagram user.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
metric | string | no | Comma-separated list of metrics (e.g. “impressions,reach,profile_views,follower_count”) |
period | string | no | Aggregation period: “day”, “week”, “days_28”, “month”, or “lifetime” |
since | string | no | Start date (UNIX timestamp or ISO date) |
until | string | no | End date (UNIX timestamp or ISO date) |
Example
local result = app.integrations.instagram.list_insights({
metric = "impressions,reach,follower_count",
period = "day"
})
for _, insight in ipairs(result.data) do
print(insight.name .. ":")
for _, value in ipairs(insight.values) do
print(" " .. value.end_time .. " = " .. tostring(value.value))
end
end
get_current_user
Get the currently authenticated Instagram user profile.
Parameters
None.
Example
local result = app.integrations.instagram.get_current_user()
print("Logged in as: @" .. (result.username or ""))
print("Followers: " .. (result.followers_count or 0))
print("Following: " .. (result.follows_count or 0))
print("Media count: " .. (result.media_count or 0))
Multi-Account Usage
If you have multiple Instagram accounts configured, use account-specific namespaces:
-- Default account (always works)
app.integrations.instagram.function_name({...})
-- Explicit default (portable across setups)
app.integrations.instagram.default.function_name({...})
-- Named accounts
app.integrations.instagram.brand_account.function_name({...})
app.integrations.instagram.agency.function_name({...})
All functions are identical across accounts — only the credentials differ.
Raw agent markdown
# Instagram — Lua API Reference
## list_media
List media published by the authenticated Instagram user.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Number of media items to return per page |
| `after` | string | no | Pagination cursor — return items after this cursor |
| `before` | string | no | Pagination cursor — return items before this cursor |
| `fields` | string | no | Comma-separated fields to return |
### Example
```lua
local result = app.integrations.instagram.list_media({
limit = 25
})
for _, media in ipairs(result.data) do
print(media.id .. ": " .. (media.caption or "No caption") .. " (" .. media.media_type .. ")")
end
-- Use paging cursor for next page
if result.paging and result.paging.cursors then
local next = app.integrations.instagram.list_media({
limit = 25,
after = result.paging.cursors.after
})
end
```
---
## get_media
Get details of a specific Instagram media item by ID.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `mediaId` | string | yes | The media ID to retrieve |
| `fields` | string | no | Comma-separated fields to return |
### Example
```lua
local result = app.integrations.instagram.get_media({
mediaId = "17895695668004550"
})
print(result.caption)
print(result.media_type)
print(result.media_url)
print("Likes: " .. (result.like_count or 0))
```
---
## create_media
Publish a new media item (photo or video) to Instagram.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `imageUrl` | string | yes | URL of the image or video to publish |
| `caption` | string | no | Caption text for the media post |
| `mediaType` | string | no | Type of media: "IMAGE", "VIDEO", or "CAROUSEL" |
| `publish` | boolean | no | Publish immediately (default true). Set false to create container only |
### Example
```lua
local result = app.integrations.instagram.create_media({
imageUrl = "https://example.com/photo.jpg",
caption = "Check out our latest product launch! 🚀"
})
print("Published media ID: " .. result.id)
```
---
## list_comments
List comments on a specific Instagram media item.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `mediaId` | string | yes | The media ID to list comments for |
| `limit` | integer | no | Number of comments to return per page |
| `after` | string | no | Pagination cursor — return comments after this cursor |
### Example
```lua
local result = app.integrations.instagram.list_comments({
mediaId = "17895695668004550",
limit = 20
})
for _, comment in ipairs(result.data) do
print(comment.username .. ": " .. comment.text)
end
```
---
## get_comment
Get details of a specific Instagram comment by ID.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `commentId` | string | yes | The comment ID to retrieve |
### Example
```lua
local result = app.integrations.instagram.get_comment({
commentId = "17853788044894720"
})
print(result.username .. ": " .. result.text)
print("Likes: " .. (result.like_count or 0))
```
---
## list_insights
Get account-level insights and performance metrics for the authenticated Instagram user.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `metric` | string | no | Comma-separated list of metrics (e.g. "impressions,reach,profile_views,follower_count") |
| `period` | string | no | Aggregation period: "day", "week", "days_28", "month", or "lifetime" |
| `since` | string | no | Start date (UNIX timestamp or ISO date) |
| `until` | string | no | End date (UNIX timestamp or ISO date) |
### Example
```lua
local result = app.integrations.instagram.list_insights({
metric = "impressions,reach,follower_count",
period = "day"
})
for _, insight in ipairs(result.data) do
print(insight.name .. ":")
for _, value in ipairs(insight.values) do
print(" " .. value.end_time .. " = " .. tostring(value.value))
end
end
```
---
## get_current_user
Get the currently authenticated Instagram user profile.
### Parameters
None.
### Example
```lua
local result = app.integrations.instagram.get_current_user()
print("Logged in as: @" .. (result.username or ""))
print("Followers: " .. (result.followers_count or 0))
print("Following: " .. (result.follows_count or 0))
print("Media count: " .. (result.media_count or 0))
```
---
## Multi-Account Usage
If you have multiple Instagram accounts configured, use account-specific namespaces:
```lua
-- Default account (always works)
app.integrations.instagram.function_name({...})
-- Explicit default (portable across setups)
app.integrations.instagram.default.function_name({...})
-- Named accounts
app.integrations.instagram.brand_account.function_name({...})
app.integrations.instagram.agency.function_name({...})
```
All functions are identical across accounts — only the credentials differ. local result = app.integrations.instagram.list_media({limit = 1, after = "example_after", before = "example_before", fields = "example_fields"})
print(result) Functions
list_media Read
List media published by the authenticated Instagram user. Returns media IDs, captions, types, URLs, and timestamps. Supports cursor-based pagination.
- Lua path
app.integrations.instagram.list_media- Full name
instagram.instagram_list_media
| Parameter | Type | Required | Description |
|---|---|---|---|
limit | integer | no | Number of media items to return per page. |
after | string | no | Pagination cursor — return items after this cursor. |
before | string | no | Pagination cursor — return items before this cursor. |
fields | string | no | Comma-separated list of fields to return (e.g. "id,caption,media_type,media_url,permalink,timestamp,username"). |
get_media Read
Get details of a specific Instagram media item by its ID. Returns caption, media type, URL, timestamp, like count, and comment count.
- Lua path
app.integrations.instagram.get_media- Full name
instagram.instagram_get_media
| Parameter | Type | Required | Description |
|---|---|---|---|
mediaId | string | yes | The media ID to retrieve. |
fields | string | no | Comma-separated list of fields to return. |
create_media Write
Publish a new media item (photo or video) to Instagram. Provide the media URL and an optional caption. The media is published immediately unless publish is set to false.
- Lua path
app.integrations.instagram.create_media- Full name
instagram.instagram_create_media
| Parameter | Type | Required | Description |
|---|---|---|---|
imageUrl | string | yes | URL of the image or video to publish. |
caption | string | no | Caption text for the media post. |
mediaType | string | no | Type of media: "IMAGE", "VIDEO", or "CAROUSEL". Defaults to "IMAGE". |
publish | boolean | no | Whether to publish immediately (default true). Set to false to create a container only. |
list_comments Read
List comments on a specific Instagram media item. Returns comment IDs, text, timestamps, usernames, and like counts. Supports pagination.
- Lua path
app.integrations.instagram.list_comments- Full name
instagram.instagram_list_comments
| Parameter | Type | Required | Description |
|---|---|---|---|
mediaId | string | yes | The media ID to list comments for. |
limit | integer | no | Number of comments to return per page. |
after | string | no | Pagination cursor — return comments after this cursor. |
get_comment Read
Get details of a specific Instagram comment by its ID. Returns the comment text, timestamp, username, and like count.
- Lua path
app.integrations.instagram.get_comment- Full name
instagram.instagram_get_comment
| Parameter | Type | Required | Description |
|---|---|---|---|
commentId | string | yes | The comment ID to retrieve. |
list_insights Read
Get account-level insights and performance metrics for the authenticated Instagram user. Supports metrics like impressions, reach, follower count, and profile views with configurable time periods.
- Lua path
app.integrations.instagram.list_insights- Full name
instagram.instagram_list_insights
| Parameter | Type | Required | Description |
|---|---|---|---|
metric | string | no | Comma-separated list of insight metrics (e.g. "impressions,reach,profile_views,follower_count"). |
period | string | no | Aggregation period: "day", "week", "days_28", "month", or "lifetime". Defaults to "day". |
since | string | no | Start date for the insight data (UNIX timestamp or ISO date). |
until | string | no | End date for the insight data (UNIX timestamp or ISO date). |
get_current_user Read
Get the currently authenticated Instagram user profile. Returns user ID, username, name, account type, media count, and follower/following counts.
- Lua path
app.integrations.instagram.get_current_user- Full name
instagram.instagram_get_current_user
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||