productivity
Facebook Lua API for KosmoKrator Agents
Agent-facing Lua documentation and function reference for the Facebook KosmoKrator integration.Lua Namespace
Agents call this integration through app.integrations.facebook.*.
Use lua_read_doc("integrations.facebook") 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
Facebook workflow without starting an interactive agent session.
kosmo integrations:lua --eval 'dump(app.integrations.facebook.list_pages({fields = "example_fields", limit = 1}))' --json kosmo integrations:lua --eval 'print(docs.read("facebook"))' --json
kosmo integrations:lua --eval 'print(docs.read("facebook.list_pages"))' --json Workflow file
Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.
local facebook = app.integrations.facebook
local result = facebook.list_pages({fields = "example_fields", limit = 1})
dump(result) kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json integrations:lua exposes app.integrations.facebook, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.facebook.default.* or app.integrations.facebook.work.* when you configured named credential accounts.
MCP-only Lua
If the script only needs configured MCP servers and does not need Facebook, 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.
Facebook — Lua API Reference
list_pages
List all Facebook Pages the authenticated user manages.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
fields | string | no | Comma-separated fields (e.g. "id,name,category,fan_count,about"). Defaults to "id,name,category". |
limit | integer | no | Max pages per request. |
Example
local result = app.integrations.facebook.list_pages({
fields = "id,name,fan_count,category"
})
for _, page in ipairs(result.data) do
print(page.name .. " (ID: " .. page.id .. ", Fans: " .. page.fan_count .. ")")
end
get_page
Get details for a specific Facebook Page.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
page_id | string | yes | The Facebook Page ID. |
fields | string | no | Comma-separated fields. Defaults to "id,name,category,fan_count,about". |
Example
local result = app.integrations.facebook.get_page({
page_id = "123456789",
fields = "id,name,fan_count,about,website"
})
print(result.name .. " — " .. result.fan_count .. " followers")
list_posts
List posts published by a Facebook Page.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
page_id | string | yes | The Facebook Page ID. |
fields | string | no | Comma-separated fields per post. Defaults to "id,message,created_time". |
limit | integer | no | Max posts per request. |
since | string | no | Only posts after this timestamp/date. |
until | string | no | Only posts before this timestamp/date. |
Example
local result = app.integrations.facebook.list_posts({
page_id = "123456789",
fields = "id,message,created_time",
limit = 10
})
for _, post in ipairs(result.data) do
print(post.created_time .. ": " .. (post.message or "(no text)"))
end
create_post
Publish a new post on a Facebook Page.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
page_id | string | yes | The Facebook Page ID. |
message | string | yes | Post body text. |
link | string | no | URL to attach to the post. |
scheduled_publish_time | string | no | UNIX timestamp for scheduled publishing. |
Example
-- Publish immediately
local result = app.integrations.facebook.create_post({
page_id = "123456789",
message = "Check out our latest blog post!",
link = "https://example.com/blog"
})
print("Published post ID: " .. result.id)
-- Schedule for later
local result = app.integrations.facebook.create_post({
page_id = "123456789",
message = "Scheduled post content",
scheduled_publish_time = "1735689600"
})
get_post
Get details for a specific Facebook post.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
post_id | string | yes | The Facebook Post ID (e.g. "pageId_postId"). |
fields | string | no | Comma-separated fields. Defaults to "id,message,created_time,attachments". |
Example
local result = app.integrations.facebook.get_post({
post_id = "123456789_987654321",
fields = "id,message,created_time,attachments,shares"
})
print(result.message)
list_insights
Get engagement and performance metrics for a Facebook Page.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
page_id | string | yes | The Facebook Page ID. |
metric | string | no | Comma-separated metric names. Omit for all available metrics. |
period | string | no | Aggregation period: "day", "week", "days_28", "month", "lifetime". Defaults to "day". |
since | string | no | Start date (UNIX timestamp or ISO date). |
until | string | no | End date (UNIX timestamp or ISO date). |
Common Metrics
| Metric | Description |
|---|---|
page_impressions | Total impressions of the page |
page_engaged_users | Users who engaged with the page |
page_post_engagements | Engagements on page posts |
page_fans | Total page followers/fans |
page_views_total | Total page views |
page_actions_post_reactions_total | Reactions on page posts |
Example
local result = app.integrations.facebook.list_insights({
page_id = "123456789",
metric = "page_impressions,page_engaged_users",
period = "day",
since = "2026-01-01",
until = "2026-01-31"
})
for _, insight in ipairs(result.data) do
print(insight.name .. ":")
for _, val in ipairs(insight.values) do
print(" " .. val.end_time .. " = " .. val.value)
end
end
get_current_user
Get the authenticated user’s Facebook profile information.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
fields | string | no | Comma-separated fields. Defaults to "id,name". |
Example
local result = app.integrations.facebook.get_current_user({
fields = "id,name,picture"
})
print("Authenticated as: " .. result.name .. " (ID: " .. result.id .. ")")
Multi-Account Usage
If you have multiple Facebook accounts configured, use account-specific namespaces:
-- Default account (always works)
app.integrations.facebook.list_pages({})
-- Explicit default (portable across setups)
app.integrations.facebook.default.list_pages({})
-- Named accounts
app.integrations.facebook.work.list_pages({})
app.integrations.facebook.client_page.list_pages({})
All functions are identical across accounts — only the credentials differ.
Raw agent markdown
# Facebook — Lua API Reference
## list_pages
List all Facebook Pages the authenticated user manages.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `fields` | string | no | Comma-separated fields (e.g. `"id,name,category,fan_count,about"`). Defaults to `"id,name,category"`. |
| `limit` | integer | no | Max pages per request. |
### Example
```lua
local result = app.integrations.facebook.list_pages({
fields = "id,name,fan_count,category"
})
for _, page in ipairs(result.data) do
print(page.name .. " (ID: " .. page.id .. ", Fans: " .. page.fan_count .. ")")
end
```
---
## get_page
Get details for a specific Facebook Page.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page_id` | string | yes | The Facebook Page ID. |
| `fields` | string | no | Comma-separated fields. Defaults to `"id,name,category,fan_count,about"`. |
### Example
```lua
local result = app.integrations.facebook.get_page({
page_id = "123456789",
fields = "id,name,fan_count,about,website"
})
print(result.name .. " — " .. result.fan_count .. " followers")
```
---
## list_posts
List posts published by a Facebook Page.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page_id` | string | yes | The Facebook Page ID. |
| `fields` | string | no | Comma-separated fields per post. Defaults to `"id,message,created_time"`. |
| `limit` | integer | no | Max posts per request. |
| `since` | string | no | Only posts after this timestamp/date. |
| `until` | string | no | Only posts before this timestamp/date. |
### Example
```lua
local result = app.integrations.facebook.list_posts({
page_id = "123456789",
fields = "id,message,created_time",
limit = 10
})
for _, post in ipairs(result.data) do
print(post.created_time .. ": " .. (post.message or "(no text)"))
end
```
---
## create_post
Publish a new post on a Facebook Page.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page_id` | string | yes | The Facebook Page ID. |
| `message` | string | yes | Post body text. |
| `link` | string | no | URL to attach to the post. |
| `scheduled_publish_time` | string | no | UNIX timestamp for scheduled publishing. |
### Example
```lua
-- Publish immediately
local result = app.integrations.facebook.create_post({
page_id = "123456789",
message = "Check out our latest blog post!",
link = "https://example.com/blog"
})
print("Published post ID: " .. result.id)
-- Schedule for later
local result = app.integrations.facebook.create_post({
page_id = "123456789",
message = "Scheduled post content",
scheduled_publish_time = "1735689600"
})
```
---
## get_post
Get details for a specific Facebook post.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `post_id` | string | yes | The Facebook Post ID (e.g. `"pageId_postId"`). |
| `fields` | string | no | Comma-separated fields. Defaults to `"id,message,created_time,attachments"`. |
### Example
```lua
local result = app.integrations.facebook.get_post({
post_id = "123456789_987654321",
fields = "id,message,created_time,attachments,shares"
})
print(result.message)
```
---
## list_insights
Get engagement and performance metrics for a Facebook Page.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page_id` | string | yes | The Facebook Page ID. |
| `metric` | string | no | Comma-separated metric names. Omit for all available metrics. |
| `period` | string | no | Aggregation period: `"day"`, `"week"`, `"days_28"`, `"month"`, `"lifetime"`. Defaults to `"day"`. |
| `since` | string | no | Start date (UNIX timestamp or ISO date). |
| `until` | string | no | End date (UNIX timestamp or ISO date). |
### Common Metrics
| Metric | Description |
|--------|-------------|
| `page_impressions` | Total impressions of the page |
| `page_engaged_users` | Users who engaged with the page |
| `page_post_engagements` | Engagements on page posts |
| `page_fans` | Total page followers/fans |
| `page_views_total` | Total page views |
| `page_actions_post_reactions_total` | Reactions on page posts |
### Example
```lua
local result = app.integrations.facebook.list_insights({
page_id = "123456789",
metric = "page_impressions,page_engaged_users",
period = "day",
since = "2026-01-01",
until = "2026-01-31"
})
for _, insight in ipairs(result.data) do
print(insight.name .. ":")
for _, val in ipairs(insight.values) do
print(" " .. val.end_time .. " = " .. val.value)
end
end
```
---
## get_current_user
Get the authenticated user's Facebook profile information.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `fields` | string | no | Comma-separated fields. Defaults to `"id,name"`. |
### Example
```lua
local result = app.integrations.facebook.get_current_user({
fields = "id,name,picture"
})
print("Authenticated as: " .. result.name .. " (ID: " .. result.id .. ")")
```
---
## Multi-Account Usage
If you have multiple Facebook accounts configured, use account-specific namespaces:
```lua
-- Default account (always works)
app.integrations.facebook.list_pages({})
-- Explicit default (portable across setups)
app.integrations.facebook.default.list_pages({})
-- Named accounts
app.integrations.facebook.work.list_pages({})
app.integrations.facebook.client_page.list_pages({})
```
All functions are identical across accounts — only the credentials differ. local result = app.integrations.facebook.list_pages({fields = "example_fields", limit = 1})
print(result) Functions
list_pages Read
List all Facebook Pages the authenticated user manages. Returns page IDs, names, and access tokens for further operations.
- Lua path
app.integrations.facebook.list_pages- Full name
facebook.facebook_list_pages
| Parameter | Type | Required | Description |
|---|---|---|---|
fields | string | no | Comma-separated list of fields to return per page (e.g. "id,name,category,fan_count,about"). Defaults to "id,name,category". |
limit | integer | no | Maximum number of pages to return per request. |
get_page Read
Get details for a specific Facebook Page by its ID. Returns page name, category, follower count, and other metadata.
- Lua path
app.integrations.facebook.get_page- Full name
facebook.facebook_get_page
| Parameter | Type | Required | Description |
|---|---|---|---|
page_id | string | yes | The Facebook Page ID. |
fields | string | no | Comma-separated list of fields to return (e.g. "id,name,category,fan_count,about,website,phone"). Defaults to "id,name,category,fan_count,about". |
list_posts Read
List posts published by a Facebook Page. Returns post IDs, messages, creation times, and engagement metrics.
- Lua path
app.integrations.facebook.list_posts- Full name
facebook.facebook_list_posts
| Parameter | Type | Required | Description |
|---|---|---|---|
page_id | string | yes | The Facebook Page ID. |
fields | string | no | Comma-separated list of fields to return per post (e.g. "id,message,created_time,attachments,insights"). Defaults to "id,message,created_time". |
limit | integer | no | Maximum number of posts to return per request. |
since | string | no | Only return posts created after this UNIX timestamp or ISO date. |
until | string | no | Only return posts created before this UNIX timestamp or ISO date. |
create_post Write
Publish a new post on a Facebook Page. The post will appear on the Page's timeline immediately unless scheduled.
- Lua path
app.integrations.facebook.create_post- Full name
facebook.facebook_create_post
| Parameter | Type | Required | Description |
|---|---|---|---|
page_id | string | yes | The Facebook Page ID to publish the post on. |
message | string | yes | The text content of the post. |
link | string | no | A URL to attach to the post (e.g. "https://example.com/article"). |
scheduled_publish_time | string | no | UNIX timestamp to schedule the post for future publication. The post will be saved as a draft until this time. |
get_post Read
Get details for a specific Facebook post by its ID. Returns the post content, creation time, and engagement metrics.
- Lua path
app.integrations.facebook.get_post- Full name
facebook.facebook_get_post
| Parameter | Type | Required | Description |
|---|---|---|---|
post_id | string | yes | The Facebook Post ID. |
fields | string | no | Comma-separated list of fields to return (e.g. "id,message,created_time,attachments,shares,likes.summary(true)"). Defaults to "id,message,created_time,attachments". |
list_insights Read
Get engagement and performance metrics (insights) for a Facebook Page. Supports metrics like page_impressions, page_engaged_users, page_post_engagements, and more.
- Lua path
app.integrations.facebook.list_insights- Full name
facebook.facebook_list_insights
| Parameter | Type | Required | Description |
|---|---|---|---|
page_id | string | yes | The Facebook Page ID. |
metric | string | no | Comma-separated list of insight metrics to retrieve (e.g. "page_impressions,page_engaged_users,page_post_engagements"). Omit to return all available metrics. |
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 authenticated user's Facebook profile information, including name and user ID.
- Lua path
app.integrations.facebook.get_current_user- Full name
facebook.facebook_get_current_user
| Parameter | Type | Required | Description |
|---|---|---|---|
fields | string | no | Comma-separated list of fields to return (e.g. "id,name,email,picture"). Defaults to "id,name". |