KosmoKrator

communication

SendGrid Lua API for KosmoKrator Agents

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

7 functions 6 read 1 write API key auth

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.

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 = "[email protected]",
    name = "My App"
  },
  to = {
    { email = "[email protected]", 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 = "[email protected]",
    name = "My App"
  },
  to = {
    { email = "[email protected]", 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.sendgrid_list_contacts({
  page_size = 1,
  page_token = "example_page_token"
})
print(result)

Functions

sendgrid_list_contacts

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

Operation
Read read
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.

sendgrid_send_email

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

Operation
Write write
Full name
sendgrid.sendgrid_send_email
ParameterTypeRequiredDescription
from object yes Sender details as an object with "email" and optionally "name" keys, e.g. {"email": "[email protected]", "name": "My App"}.
to array yes Array of recipient objects, each with "email" and optionally "name", e.g. [{"email": "[email protected]", "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.

sendgrid_get_contact

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

Operation
Read read
Full name
sendgrid.sendgrid_get_contact
ParameterTypeRequiredDescription
id string yes The ID of the contact to retrieve.

sendgrid_get_current_user

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

Operation
Read read
Full name
sendgrid.sendgrid_get_current_user
ParameterTypeRequiredDescription
No parameters.

sendgrid_get_template

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

Operation
Read read
Full name
sendgrid.sendgrid_get_template
ParameterTypeRequiredDescription
id string yes The ID of the template to retrieve.

sendgrid_list_emails

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

Operation
Read read
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\"").

sendgrid_list_templates

List email templates in your SendGrid account. Supports pagination.

Operation
Read read
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.