KosmoKrator

sales

Capsule CRM Lua API for KosmoKrator Agents

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

7 functions 6 read 1 write Bearer token auth

Lua Namespace

Agents call this integration through app.integrations.capsule.*. Use lua_read_doc("integrations.capsule") inside KosmoKrator to discover the same reference at runtime.

Agent-Facing Lua Docs

This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.

Capsule CRM — Lua API Reference

list_contacts

List contacts (people and organisations) from Capsule CRM.

Parameters

NameTypeRequiredDescription
pageintegernoPage number for pagination (default: 1)
per_pageintegernoNumber of contacts per page, max 100 (default: 50)

Examples

-- List first page of contacts
local result = app.integrations.capsule.list_contacts({})

-- List second page with 25 results
local result = app.integrations.capsule.list_contacts({
  page = 2,
  per_page = 25
})

for _, contact in ipairs(result.parties) do
  print(contact.id .. ": " .. (contact.firstName or "") .. " " .. (contact.lastName or ""))
end

get_contact

Retrieve a single contact (person or organisation) by ID.

Parameters

NameTypeRequiredDescription
idintegeryesThe contact (party) ID

Examples

local result = app.integrations.capsule.get_contact({ id = 12345 })
local party = result.party

print(party.firstName .. " " .. party.lastName)
print("Type: " .. party.type)

create_contact

Create a new person or organisation in Capsule CRM.

Parameters

NameTypeRequiredDescription
typestringnoContact type: “person” (default) or “organisation”
firstNamestringyesFirst name of the contact
lastNamestringyesLast name of the contact
emailAddressesarraynoEmail addresses, e.g. {{address = "[email protected]"}}

Examples

-- Create a person contact with email
local result = app.integrations.capsule.create_contact({
  type = "person",
  firstName = "Jane",
  lastName = "Doe",
  emailAddresses = {
    { address = "[email protected]" }
  }
})

print("Created contact ID: " .. result.party.id)

-- Create an organisation
local result = app.integrations.capsule.create_contact({
  type = "organisation",
  firstName = "Acme Corp",
  lastName = ""
})

list_opportunities

List sales opportunities from Capsule CRM.

Parameters

NameTypeRequiredDescription
pageintegernoPage number for pagination (default: 1)
per_pageintegernoNumber of opportunities per page, max 100 (default: 50)
statusstringnoFilter by status: OPEN, WON, LOST, or CLOSED

Examples

-- List all open opportunities
local result = app.integrations.capsule.list_opportunities({
  status = "OPEN"
})

for _, opp in ipairs(result.opportunities) do
  print(opp.id .. ": " .. opp.name .. " - " .. (opp.value or "no value"))
end

-- Paginated list of all opportunities
local result = app.integrations.capsule.list_opportunities({
  page = 1,
  per_page = 100
})

get_opportunity

Retrieve a single sales opportunity by ID.

Parameters

NameTypeRequiredDescription
idintegeryesThe opportunity ID

Examples

local result = app.integrations.capsule.get_opportunity({ id = 67890 })
local opp = result.opportunity

print(opp.name)
print("Value: " .. (opp.value or "N/A"))
print("Status: " .. opp.status)

list_tasks

List tasks from Capsule CRM.

Parameters

NameTypeRequiredDescription
pageintegernoPage number for pagination (default: 1)
per_pageintegernoNumber of tasks per page, max 100 (default: 50)
statusstringnoFilter by status: OPEN or COMPLETED

Examples

-- List open tasks
local result = app.integrations.capsule.list_tasks({
  status = "OPEN"
})

for _, task in ipairs(result.tasks) do
  print(task.id .. ": " .. task.description)
end

-- Completed tasks, page 2
local result = app.integrations.capsule.list_tasks({
  status = "COMPLETED",
  page = 2,
  per_page = 25
})

get_current_user

Get the currently authenticated Capsule CRM user. Use this to verify credentials or identify the connected account.

Parameters

None.

Examples

local result = app.integrations.capsule.get_current_user({})
local user = result.user

print("Connected as: " .. user.firstName .. " " .. user.lastName)
print("Email: " .. user.emailAddress)

Multi-Account Usage

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

-- Default account (always works)
app.integrations.capsule.list_contacts({})

-- Explicit default (portable across setups)
app.integrations.capsule.default.list_contacts({})

-- Named accounts
app.integrations.capsule.work.list_contacts({})
app.integrations.capsule.personal.list_contacts({})

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

Raw agent markdown
# Capsule CRM — Lua API Reference

## list_contacts

List contacts (people and organisations) from Capsule CRM.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page` | integer | no | Page number for pagination (default: 1) |
| `per_page` | integer | no | Number of contacts per page, max 100 (default: 50) |

### Examples

```lua
-- List first page of contacts
local result = app.integrations.capsule.list_contacts({})

-- List second page with 25 results
local result = app.integrations.capsule.list_contacts({
  page = 2,
  per_page = 25
})

for _, contact in ipairs(result.parties) do
  print(contact.id .. ": " .. (contact.firstName or "") .. " " .. (contact.lastName or ""))
end
```

---

## get_contact

Retrieve a single contact (person or organisation) by ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | integer | yes | The contact (party) ID |

### Examples

```lua
local result = app.integrations.capsule.get_contact({ id = 12345 })
local party = result.party

print(party.firstName .. " " .. party.lastName)
print("Type: " .. party.type)
```

---

## create_contact

Create a new person or organisation in Capsule CRM.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `type` | string | no | Contact type: "person" (default) or "organisation" |
| `firstName` | string | yes | First name of the contact |
| `lastName` | string | yes | Last name of the contact |
| `emailAddresses` | array | no | Email addresses, e.g. `{{address = "[email protected]"}}` |

### Examples

```lua
-- Create a person contact with email
local result = app.integrations.capsule.create_contact({
  type = "person",
  firstName = "Jane",
  lastName = "Doe",
  emailAddresses = {
    { address = "[email protected]" }
  }
})

print("Created contact ID: " .. result.party.id)

-- Create an organisation
local result = app.integrations.capsule.create_contact({
  type = "organisation",
  firstName = "Acme Corp",
  lastName = ""
})
```

---

## list_opportunities

List sales opportunities from Capsule CRM.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page` | integer | no | Page number for pagination (default: 1) |
| `per_page` | integer | no | Number of opportunities per page, max 100 (default: 50) |
| `status` | string | no | Filter by status: OPEN, WON, LOST, or CLOSED |

### Examples

```lua
-- List all open opportunities
local result = app.integrations.capsule.list_opportunities({
  status = "OPEN"
})

for _, opp in ipairs(result.opportunities) do
  print(opp.id .. ": " .. opp.name .. " - " .. (opp.value or "no value"))
end

-- Paginated list of all opportunities
local result = app.integrations.capsule.list_opportunities({
  page = 1,
  per_page = 100
})
```

---

## get_opportunity

Retrieve a single sales opportunity by ID.

### Parameters

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

### Examples

```lua
local result = app.integrations.capsule.get_opportunity({ id = 67890 })
local opp = result.opportunity

print(opp.name)
print("Value: " .. (opp.value or "N/A"))
print("Status: " .. opp.status)
```

---

## list_tasks

List tasks from Capsule CRM.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page` | integer | no | Page number for pagination (default: 1) |
| `per_page` | integer | no | Number of tasks per page, max 100 (default: 50) |
| `status` | string | no | Filter by status: OPEN or COMPLETED |

### Examples

```lua
-- List open tasks
local result = app.integrations.capsule.list_tasks({
  status = "OPEN"
})

for _, task in ipairs(result.tasks) do
  print(task.id .. ": " .. task.description)
end

-- Completed tasks, page 2
local result = app.integrations.capsule.list_tasks({
  status = "COMPLETED",
  page = 2,
  per_page = 25
})
```

---

## get_current_user

Get the currently authenticated Capsule CRM user. Use this to verify credentials or identify the connected account.

### Parameters

None.

### Examples

```lua
local result = app.integrations.capsule.get_current_user({})
local user = result.user

print("Connected as: " .. user.firstName .. " " .. user.lastName)
print("Email: " .. user.emailAddress)
```

---

## Multi-Account Usage

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

```lua
-- Default account (always works)
app.integrations.capsule.list_contacts({})

-- Explicit default (portable across setups)
app.integrations.capsule.default.list_contacts({})

-- Named accounts
app.integrations.capsule.work.list_contacts({})
app.integrations.capsule.personal.list_contacts({})
```

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

Metadata-Derived Lua Example

local result = app.integrations.capsule.capsule_list_contacts({
  page = 1,
  per_page = 1
})
print(result)

Functions

capsule_list_contacts

List contacts (people and organisations) from Capsule CRM. Returns paginated results with contact details.

Operation
Read read
Full name
capsule.capsule_list_contacts
ParameterTypeRequiredDescription
page integer no Page number for pagination (default: 1).
per_page integer no Number of contacts per page, max 100 (default: 50).

capsule_get_contact

Retrieve a single contact (person or organisation) from Capsule CRM by ID.

Operation
Read read
Full name
capsule.capsule_get_contact
ParameterTypeRequiredDescription
id integer yes The contact (party) ID.

capsule_create_contact

Create a new contact (person or organisation) in Capsule CRM. Provide at least a first name and last name for a person contact.

Operation
Write write
Full name
capsule.capsule_create_contact
ParameterTypeRequiredDescription
type string no Contact type: "person" (default) or "organisation".
firstName string yes First name of the contact.
lastName string yes Last name of the contact.
emailAddresses array no Email addresses, e.g. [{"address":"[email protected]"}].

capsule_list_opportunities

List sales opportunities from Capsule CRM. Optionally filter by status (OPEN, WON, LOST, CLOSED). Returns paginated results.

Operation
Read read
Full name
capsule.capsule_list_opportunities
ParameterTypeRequiredDescription
page integer no Page number for pagination (default: 1).
per_page integer no Number of opportunities per page, max 100 (default: 50).
status string no Filter by status: OPEN, WON, LOST, or CLOSED.

capsule_get_opportunity

Retrieve a single sales opportunity from Capsule CRM by ID.

Operation
Read read
Full name
capsule.capsule_get_opportunity
ParameterTypeRequiredDescription
id integer yes The opportunity ID.

capsule_list_tasks

List tasks from Capsule CRM. Optionally filter by status (OPEN, COMPLETED). Returns paginated results.

Operation
Read read
Full name
capsule.capsule_list_tasks
ParameterTypeRequiredDescription
page integer no Page number for pagination (default: 1).
per_page integer no Number of tasks per page, max 100 (default: 50).
status string no Filter by status: OPEN or COMPLETED.

capsule_get_current_user

Get the currently authenticated Capsule CRM user. Use this to verify credentials or identify the connected account.

Operation
Read read
Full name
capsule.capsule_get_current_user
ParameterTypeRequiredDescription
No parameters.