KosmoKrator

productivity

SendGrid Lua API for KosmoKrator Agents

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

Lua Namespace

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

Inline Lua call
kosmo integrations:lua --eval 'dump(app.integrations.sendgrid.list_contacts({page_size = 1, page_token = "example_page_token"}))' --json
Read Lua docs headlessly
kosmo integrations:lua --eval 'print(docs.read("sendgrid"))' --json
kosmo integrations:lua --eval 'print(docs.read("sendgrid.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 sendgrid = app.integrations.sendgrid
local result = sendgrid.list_contacts({page_size = 1, page_token = "example_page_token"})

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.sendgrid, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.sendgrid.default.* or app.integrations.sendgrid.work.* when you configured named credential accounts.

MCP-only Lua

If the script only needs configured MCP servers and does not need SendGrid, 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.

SendGrid — Lua API Reference

list_emails

List emails in your SendGrid account with optional filtering and pagination.

Parameters

NameTypeRequiredDescription
limitintegernoMaximum number of emails to return (default: 20, max: 100)
querystringnoSearch query to filter emails (e.g., subject="Welcome")

Example

local result = app.integrations.sendgrid.list_emails({
  limit = 10,
  query = 'subject="Welcome"'
})

for _, email in ipairs(result.messages) do
  print(email.from_email .. " -> " .. email.subject)
end

send_email

Send an email via SendGrid.

Parameters

NameTypeRequiredDescription
fromobjectyesSender with email and optionally name keys
toarrayyesArray of recipient objects, each with email and optionally name
subjectstringyesThe email subject line
htmlContentstringnoHTML body of the email
textContentstringnoPlain text body of the email

Example

local result = app.integrations.sendgrid.send_email({
  from = {
    email = "noreply@example.com",
    name = "My App"
  },
  to = {
    { email = "user@example.com", name = "John" }
  },
  subject = "Welcome!",
  htmlContent = "<h1>Hello!</h1><p>Welcome to our service.</p>",
  textContent = "Hello! Welcome to our service."
})

print("Email sent successfully")

list_templates

List email templates in your SendGrid account.

Parameters

NameTypeRequiredDescription
page_sizeintegernoNumber of templates to return per page (default: 20, max: 100)
page_tokenstringnoToken for the next page of results

Example

local result = app.integrations.sendgrid.list_templates({
  page_size = 10
})

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

get_template

Get details of a specific email template by its ID.

Parameters

NameTypeRequiredDescription
idstringyesThe ID of the template to retrieve

Example

local result = app.integrations.sendgrid.get_template({
  id = "d-abc123def456"
})

print("Template: " .. result.name)

if result.versions then
  for _, version in ipairs(result.versions) do
    print("  Version: " .. version.name .. " (active: " .. tostring(version.active) .. ")")
  end
end

list_contacts

List contacts in your SendGrid marketing contacts database.

Parameters

NameTypeRequiredDescription
page_sizeintegernoNumber of contacts to return per page (default: 50, max: 100)
page_tokenstringnoToken for the next page of results

Example

local result = app.integrations.sendgrid.list_contacts({
  page_size = 20
})

for _, contact in ipairs(result.result) do
  print(contact.email)
end

get_contact

Get details of a specific contact by their ID.

Parameters

NameTypeRequiredDescription
idstringyesThe ID of the contact to retrieve

Example

local result = app.integrations.sendgrid.get_contact({
  id = "abc123-def456-ghi789"
})

print("Email: " .. result.email)
print("First name: " .. (result.first_name or "N/A"))
print("Last name: " .. (result.last_name or "N/A"))

get_current_user

Get the profile of the currently authenticated SendGrid user.

Parameters

None.

Example

local result = app.integrations.sendgrid.get_current_user()

print("Email: " .. result.email)
print("Name: " .. (result.first_name or "") .. " " .. (result.last_name or ""))

Multi-Account Usage

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

-- Default account (always works)
app.integrations.sendgrid.function_name({...})

-- Explicit default (portable across setups)
app.integrations.sendgrid.default.function_name({...})

-- Named accounts
app.integrations.sendgrid.work.function_name({...})
app.integrations.sendgrid.personal.function_name({...})

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

Raw agent markdown
# SendGrid — Lua API Reference

## list_emails

List emails in your SendGrid account with optional filtering and pagination.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Maximum number of emails to return (default: 20, max: 100) |
| `query` | string | no | Search query to filter emails (e.g., `subject="Welcome"`) |

### Example

```lua
local result = app.integrations.sendgrid.list_emails({
  limit = 10,
  query = 'subject="Welcome"'
})

for _, email in ipairs(result.messages) do
  print(email.from_email .. " -> " .. email.subject)
end
```

---

## send_email

Send an email via SendGrid.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `from` | object | yes | Sender with `email` and optionally `name` keys |
| `to` | array | yes | Array of recipient objects, each with `email` and optionally `name` |
| `subject` | string | yes | The email subject line |
| `htmlContent` | string | no | HTML body of the email |
| `textContent` | string | no | Plain text body of the email |

### Example

```lua
local result = app.integrations.sendgrid.send_email({
  from = {
    email = "noreply@example.com",
    name = "My App"
  },
  to = {
    { email = "user@example.com", name = "John" }
  },
  subject = "Welcome!",
  htmlContent = "<h1>Hello!</h1><p>Welcome to our service.</p>",
  textContent = "Hello! Welcome to our service."
})

print("Email sent successfully")
```

---

## list_templates

List email templates in your SendGrid account.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page_size` | integer | no | Number of templates to return per page (default: 20, max: 100) |
| `page_token` | string | no | Token for the next page of results |

### Example

```lua
local result = app.integrations.sendgrid.list_templates({
  page_size = 10
})

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

---

## get_template

Get details of a specific email template by its ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | The ID of the template to retrieve |

### Example

```lua
local result = app.integrations.sendgrid.get_template({
  id = "d-abc123def456"
})

print("Template: " .. result.name)

if result.versions then
  for _, version in ipairs(result.versions) do
    print("  Version: " .. version.name .. " (active: " .. tostring(version.active) .. ")")
  end
end
```

---

## list_contacts

List contacts in your SendGrid marketing contacts database.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page_size` | integer | no | Number of contacts to return per page (default: 50, max: 100) |
| `page_token` | string | no | Token for the next page of results |

### Example

```lua
local result = app.integrations.sendgrid.list_contacts({
  page_size = 20
})

for _, contact in ipairs(result.result) do
  print(contact.email)
end
```

---

## get_contact

Get details of a specific contact by their ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | The ID of the contact to retrieve |

### Example

```lua
local result = app.integrations.sendgrid.get_contact({
  id = "abc123-def456-ghi789"
})

print("Email: " .. result.email)
print("First name: " .. (result.first_name or "N/A"))
print("Last name: " .. (result.last_name or "N/A"))
```

---

## get_current_user

Get the profile of the currently authenticated SendGrid user.

### Parameters

None.

### Example

```lua
local result = app.integrations.sendgrid.get_current_user()

print("Email: " .. result.email)
print("Name: " .. (result.first_name or "") .. " " .. (result.last_name or ""))
```

---

## Multi-Account Usage

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

```lua
-- Default account (always works)
app.integrations.sendgrid.function_name({...})

-- Explicit default (portable across setups)
app.integrations.sendgrid.default.function_name({...})

-- Named accounts
app.integrations.sendgrid.work.function_name({...})
app.integrations.sendgrid.personal.function_name({...})
```

All functions are identical across accounts — only the credentials differ.
Metadata-derived Lua example
local result = app.integrations.sendgrid.list_contacts({page_size = 1, page_token = "example_page_token"})
print(result)

Functions

list_contacts Read

List contacts in your SendGrid marketing contacts database. Supports pagination.

Lua path
app.integrations.sendgrid.list_contacts
Full name
sendgrid.sendgrid_list_contacts
ParameterTypeRequiredDescription
page_size integer no Number of contacts to return per page (default: 50, max: 100).
page_token string no Token for the next page of results.
email Write

Send an email via SendGrid. Specify sender, recipients, subject, and HTML or text content.

Lua path
app.integrations.sendgrid.email
Full name
sendgrid.sendgrid_send_email
ParameterTypeRequiredDescription
from object yes Sender details as an object with "email" and optionally "name" keys, e.g. {"email": "noreply@example.com", "name": "My App"}.
to array yes Array of recipient objects, each with "email" and optionally "name", e.g. [{"email": "user@example.com", "name": "John"}].
subject string yes The email subject line.
htmlContent string no HTML body of the email.
textContent string no Plain text body of the email.
get_contact Read

Get details of a specific contact in SendGrid by their contact ID. Returns email, custom fields, and list memberships.

Lua path
app.integrations.sendgrid.get_contact
Full name
sendgrid.sendgrid_get_contact
ParameterTypeRequiredDescription
id string yes The ID of the contact to retrieve.
get_current_user Read

Get the profile of the currently authenticated SendGrid user, including email, first name, and last name.

Lua path
app.integrations.sendgrid.get_current_user
Full name
sendgrid.sendgrid_get_current_user
ParameterTypeRequiredDescription
No parameters.
get_template Read

Get details of a specific email template in SendGrid by its ID. Returns template name, versions, and active version content.

Lua path
app.integrations.sendgrid.get_template
Full name
sendgrid.sendgrid_get_template
ParameterTypeRequiredDescription
id string yes The ID of the template to retrieve.
list_emails Read

List emails in your SendGrid account. Supports filtering by query and pagination.

Lua path
app.integrations.sendgrid.list_emails
Full name
sendgrid.sendgrid_list_emails
ParameterTypeRequiredDescription
limit integer no Maximum number of emails to return (default: 20, max: 100).
query string no Search query to filter emails (e.g., "subject=\"Welcome\"").
list_templates Read

List email templates in your SendGrid account. Supports pagination.

Lua path
app.integrations.sendgrid.list_templates
Full name
sendgrid.sendgrid_list_templates
ParameterTypeRequiredDescription
page_size integer no Number of templates to return per page (default: 20, max: 100).
page_token string no Token for the next page of results.