KosmoKrator

productivity

Keap Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the Keap KosmoKrator integration.

Lua Namespace

Agents call this integration through app.integrations.keap.*. Use lua_read_doc("integrations.keap") 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 Keap workflow without starting an interactive agent session.

Inline Lua call
kosmo integrations:lua --eval 'dump(app.integrations.keap.list_contacts({page = 1, limit = 1}))' --json
Read Lua docs headlessly
kosmo integrations:lua --eval 'print(docs.read("keap"))' --json
kosmo integrations:lua --eval 'print(docs.read("keap.list_contacts"))' --json

Workflow file

Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.

workflow.lua
local keap = app.integrations.keap
local result = keap.list_contacts({page = 1, limit = 1})

dump(result)
Run the workflow
kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json
Namespace note. integrations:lua exposes app.integrations.keap, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.keap.default.* or app.integrations.keap.work.* when you configured named credential accounts.

MCP-only Lua

If the script only needs configured MCP servers and does not need Keap, use the narrower mcp:lua command.

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.

Keap CRM — Lua API Reference

list_contacts

List contacts from Keap CRM with pagination.

Parameters

NameTypeRequiredDescription
pageintegernoPage number (default: 1)
limitintegernoResults per page (default: 20, max: 200)

Example

local result = app.integrations.keap.list_contacts({
  page = 1,
  limit = 20
})

for _, contact in ipairs(result.contacts) do
  print(contact.given_name .. " " .. contact.family_name)
end

get_contact

Retrieve a single contact by ID.

Parameters

NameTypeRequiredDescription
idintegeryesThe Keap contact ID

Example

local result = app.integrations.keap.get_contact({ id = 12345 })
print(result.given_name .. " " .. result.family_name)

create_contact

Create a new contact in Keap CRM.

Parameters

NameTypeRequiredDescription
first_namestringnoFirst name
last_namestringnoLast name
emailstringnoPrimary email address
company_namestringnoCompany name

At least one field is required.

Example

local result = app.integrations.keap.create_contact({
  first_name = "Jane",
  last_name = "Doe",
  email = "jane@example.com",
  company_name = "Acme Corp"
})
print("Created contact ID: " .. result.id)

list_opportunities

List sales opportunities with optional stage filter.

Parameters

NameTypeRequiredDescription
pageintegernoPage number (default: 1)
limitintegernoResults per page (default: 20, max: 200)
stagestringnoFilter by stage (e.g., “New”, “Appointment Scheduled”, “Closed Won”, “Closed Lost”)

Example

local result = app.integrations.keap.list_opportunities({
  page = 1,
  limit = 20,
  stage = "New"
})

for _, opp in ipairs(result.opportunities) do
  print(opp.title .. " — $" .. opp.value)
end

get_opportunity

Retrieve a single opportunity by ID.

Parameters

NameTypeRequiredDescription
idintegeryesThe Keap opportunity ID

Example

local result = app.integrations.keap.get_opportunity({ id = 67890 })
print(result.title .. " — Stage: " .. result.stage)

list_tags

List all tags in Keap.

Parameters

None.

Example

local result = app.integrations.keap.list_tags()

for _, tag in ipairs(result.tags) do
  print(tag.id .. ": " .. tag.name)
end

get_current_user

Get the currently authenticated Keap user.

Parameters

None.

Example

local result = app.integrations.keap.get_current_user()
print("Connected as: " .. result.first_name .. " " .. result.last_name)

Multi-Account Usage

If you have multiple Keap accounts configured, use account-specific namespaces:

-- Default account (always works)
app.integrations.keap.list_contacts({ page = 1 })

-- Explicit default (portable across setups)
app.integrations.keap.default.list_contacts({ page = 1 })

-- Named accounts
app.integrations.keap.production.list_contacts({ page = 1 })
app.integrations.keap.staging.list_contacts({ page = 1 })

All functions are identical across accounts — only the credentials differ.

Raw agent markdown
# Keap CRM — Lua API Reference

## list_contacts

List contacts from Keap CRM with pagination.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page` | integer | no | Page number (default: 1) |
| `limit` | integer | no | Results per page (default: 20, max: 200) |

### Example

```lua
local result = app.integrations.keap.list_contacts({
  page = 1,
  limit = 20
})

for _, contact in ipairs(result.contacts) do
  print(contact.given_name .. " " .. contact.family_name)
end
```

---

## get_contact

Retrieve a single contact by ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | integer | yes | The Keap contact ID |

### Example

```lua
local result = app.integrations.keap.get_contact({ id = 12345 })
print(result.given_name .. " " .. result.family_name)
```

---

## create_contact

Create a new contact in Keap CRM.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `first_name` | string | no | First name |
| `last_name` | string | no | Last name |
| `email` | string | no | Primary email address |
| `company_name` | string | no | Company name |

At least one field is required.

### Example

```lua
local result = app.integrations.keap.create_contact({
  first_name = "Jane",
  last_name = "Doe",
  email = "jane@example.com",
  company_name = "Acme Corp"
})
print("Created contact ID: " .. result.id)
```

---

## list_opportunities

List sales opportunities with optional stage filter.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page` | integer | no | Page number (default: 1) |
| `limit` | integer | no | Results per page (default: 20, max: 200) |
| `stage` | string | no | Filter by stage (e.g., "New", "Appointment Scheduled", "Closed Won", "Closed Lost") |

### Example

```lua
local result = app.integrations.keap.list_opportunities({
  page = 1,
  limit = 20,
  stage = "New"
})

for _, opp in ipairs(result.opportunities) do
  print(opp.title .. " — $" .. opp.value)
end
```

---

## get_opportunity

Retrieve a single opportunity by ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | integer | yes | The Keap opportunity ID |

### Example

```lua
local result = app.integrations.keap.get_opportunity({ id = 67890 })
print(result.title .. " — Stage: " .. result.stage)
```

---

## list_tags

List all tags in Keap.

### Parameters

None.

### Example

```lua
local result = app.integrations.keap.list_tags()

for _, tag in ipairs(result.tags) do
  print(tag.id .. ": " .. tag.name)
end
```

---

## get_current_user

Get the currently authenticated Keap user.

### Parameters

None.

### Example

```lua
local result = app.integrations.keap.get_current_user()
print("Connected as: " .. result.first_name .. " " .. result.last_name)
```

---

## Multi-Account Usage

If you have multiple Keap accounts configured, use account-specific namespaces:

```lua
-- Default account (always works)
app.integrations.keap.list_contacts({ page = 1 })

-- Explicit default (portable across setups)
app.integrations.keap.default.list_contacts({ page = 1 })

-- Named accounts
app.integrations.keap.production.list_contacts({ page = 1 })
app.integrations.keap.staging.list_contacts({ page = 1 })
```

All functions are identical across accounts — only the credentials differ.
Metadata-derived Lua example
local result = app.integrations.keap.list_contacts({page = 1, limit = 1})
print(result)

Functions

list_contacts Read

List contacts from Keap CRM. Returns paginated results with contact details including name, email, and company.

Lua path
app.integrations.keap.list_contacts
Full name
keap.keap_list_contacts
ParameterTypeRequiredDescription
page integer no Page number for pagination (default: 1).
limit integer no Number of contacts per page (default: 20, max: 200).
get_contact Read

Retrieve a single Keap contact by ID. Returns full contact details including email addresses, phone numbers, and tags.

Lua path
app.integrations.keap.get_contact
Full name
keap.keap_get_contact
ParameterTypeRequiredDescription
id integer yes The Keap contact ID.
create_contact Write

Create a new contact in Keap CRM. Provide at least a first name or last name. Email and company name are optional.

Lua path
app.integrations.keap.create_contact
Full name
keap.keap_create_contact
ParameterTypeRequiredDescription
first_name string no First name of the contact.
last_name string no Last name of the contact.
email string no Primary email address for the contact.
company_name string no Company name to associate with the contact.
list_opportunities Read

List sales opportunities from Keap CRM. Optionally filter by pipeline stage. Returns paginated results with opportunity details.

Lua path
app.integrations.keap.list_opportunities
Full name
keap.keap_list_opportunities
ParameterTypeRequiredDescription
page integer no Page number for pagination (default: 1).
limit integer no Number of opportunities per page (default: 20, max: 200).
stage string no Filter by opportunity stage (e.g., "New", "Appointment Scheduled", "Closed Won", "Closed Lost").
get_opportunity Read

Retrieve a single Keap sales opportunity by ID. Returns full details including contact, stage, value, and notes.

Lua path
app.integrations.keap.get_opportunity
Full name
keap.keap_get_opportunity
ParameterTypeRequiredDescription
id integer yes The Keap opportunity ID.
list_tags Read

List all tags in Keap. Tags are used to categorize contacts and trigger automations.

Lua path
app.integrations.keap.list_tags
Full name
keap.keap_list_tags
ParameterTypeRequiredDescription
No parameters.
get_current_user Read

Get the currently authenticated Keap user. Returns profile information for the user associated with the access token.

Lua path
app.integrations.keap.get_current_user
Full name
keap.keap_get_current_user
ParameterTypeRequiredDescription
No parameters.