KosmoKrator

other

Docusign Lua API for KosmoKrator Agents

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

8 functions 7 read 1 write Manual OAuth token auth

Lua Namespace

Agents call this integration through app.integrations.docusign.*. Use lua_read_doc("integrations.docusign") 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.

DocuSign — Lua API Reference

list_envelopes

List envelopes in the DocuSign account with optional filtering.

Parameters

NameTypeRequiredDescription
statusstringnoFilter by status: sent, delivered, completed, signed, declined, voided, or all (default: all)
from_datestringnoStart date (YYYY-MM-DD). Defaults to 30 days ago.
to_datestringnoEnd date (YYYY-MM-DD). Defaults to today.
search_textstringnoSearch envelope subjects and recipient names
countintegernoNumber of results (default: 25, max: 100)
start_positionintegernoZero-based pagination index
orderstringnoSort direction: "asc" or "desc"
order_bystringnoSort field: "last_modified", "created", or "sent"

Example

local result = app.integrations.docusign.list_envelopes({
  status = "completed",
  from_date = "2026-01-01",
  to_date = "2026-03-31",
  count = 10
})

for _, env in ipairs(result.envelopes) do
  print(env.envelopeId .. ": " .. env.subject .. " (" .. env.status .. ")")
end

get_envelope

Get detailed information about a specific envelope.

Parameters

NameTypeRequiredDescription
envelope_idstringyesThe envelope ID
includestringnoComma-separated: recipients, documents, extensions, custom_fields, tabs

Example

local result = app.integrations.docusign.get_envelope({
  envelope_id = "abc123-def456",
  include = "recipients,documents"
})

print("Subject: " .. result.emailSubject)
print("Status: " .. result.status)

create_envelope

Create a new envelope for electronic signature.

Parameters

NameTypeRequiredDescription
envelope_definitionobjectyesFull envelope definition (see below)

Envelope Definition Fields

The envelope_definition object must contain:

FieldTypeRequiredDescription
emailSubjectstringyesEmail subject line
documentsarrayyes*Array of document objects (not needed if using templateId)
templateIdstringyes*Template ID to create from (alternative to documents)
recipientsobjectyesRecipient roles: signers, ccs, etc.
statusstringno"sent" to send immediately or "created" to save as draft (default: sent)

Examples

-- Create from a template
local result = app.integrations.docusign.create_envelope({
  envelope_definition = {
    templateId = "tmpl-abc123",
    emailSubject = "Please sign the NDA",
    status = "sent",
    templateRoles = {
      {
        roleName = "signer",
        name = "Jane Doe",
        email = "[email protected]"
      }
    }
  }
})

print("Envelope created: " .. result.envelopeId)
-- Create with inline documents
local result = app.integrations.docusign.create_envelope({
  envelope_definition = {
    emailSubject = "Contract for signature",
    status = "sent",
    documents = {
      {
        documentId = "1",
        name = "Contract.pdf",
        documentBase64 = "<base64-encoded PDF>"
      }
    },
    recipients = {
      signers = {
        {
          recipientId = "1",
          name = "John Smith",
          email = "[email protected]",
          tabs = {
            signHereTabs = {
              { documentId = "1", pageNumber = "1", xPosition = "100", yPosition = "500" }
            }
          }
        }
      }
    }
  }
})

list_templates

List templates available in the DocuSign account.

Parameters

NameTypeRequiredDescription
search_textstringnoFilter by name or description
countintegernoNumber of results (default: 25)
start_positionintegernoZero-based pagination index
folder_idstringnoFilter by folder ID
orderstringnoSort direction: "asc" or "desc"
order_bystringnoSort field: "name" or "modified"

Example

local result = app.integrations.docusign.list_templates({
  search_text = "NDA",
  count = 10
})

for _, tmpl in ipairs(result.envelopeTemplates) do
  print(tmpl.templateId .. ": " .. tmpl.name)
end

get_template

Get full details for a DocuSign template.

Parameters

NameTypeRequiredDescription
template_idstringyesThe template ID

Example

local result = app.integrations.docusign.get_template({
  template_id = "tmpl-abc123"
})

print("Template: " .. result.name)
print("Documents: " .. #result.documents)

list_documents

List documents attached to an envelope.

Parameters

NameTypeRequiredDescription
envelope_idstringyesThe envelope ID

Example

local result = app.integrations.docusign.list_documents({
  envelope_id = "abc123-def456"
})

for _, doc in ipairs(result.envelopeDocuments) do
  print(doc.documentId .. ": " .. doc.name .. " (" .. doc.type .. ")")
end

get_document

Download a document from an envelope.

Parameters

NameTypeRequiredDescription
envelope_idstringyesThe envelope ID
document_idstringyesThe document ID, or "combined" for all docs as one PDF

Example

local result = app.integrations.docusign.get_document({
  envelope_id = "abc123-def456",
  document_id = "1"
})

print("Size: " .. result.size_bytes .. " bytes")
-- result.content_base64 contains the base64-encoded document

get_current_user

Get information about the authenticated DocuSign user.

Parameters

None.

Example

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

print("User: " .. result.name)
print("Email: " .. result.email)

for _, acct in ipairs(result.accounts) do
  print("Account: " .. acct.account_id .. " - " .. acct.account_name)
end

Multi-Account Usage

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

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

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

-- Named accounts
app.integrations.docusign.production.function_name({...})
app.integrations.docusign.sandbox.function_name({...})

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

Raw agent markdown
# DocuSign — Lua API Reference

## list_envelopes

List envelopes in the DocuSign account with optional filtering.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `status` | string | no | Filter by status: `sent`, `delivered`, `completed`, `signed`, `declined`, `voided`, or `all` (default: all) |
| `from_date` | string | no | Start date (YYYY-MM-DD). Defaults to 30 days ago. |
| `to_date` | string | no | End date (YYYY-MM-DD). Defaults to today. |
| `search_text` | string | no | Search envelope subjects and recipient names |
| `count` | integer | no | Number of results (default: 25, max: 100) |
| `start_position` | integer | no | Zero-based pagination index |
| `order` | string | no | Sort direction: `"asc"` or `"desc"` |
| `order_by` | string | no | Sort field: `"last_modified"`, `"created"`, or `"sent"` |

### Example

```lua
local result = app.integrations.docusign.list_envelopes({
  status = "completed",
  from_date = "2026-01-01",
  to_date = "2026-03-31",
  count = 10
})

for _, env in ipairs(result.envelopes) do
  print(env.envelopeId .. ": " .. env.subject .. " (" .. env.status .. ")")
end
```

---

## get_envelope

Get detailed information about a specific envelope.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `envelope_id` | string | yes | The envelope ID |
| `include` | string | no | Comma-separated: `recipients`, `documents`, `extensions`, `custom_fields`, `tabs` |

### Example

```lua
local result = app.integrations.docusign.get_envelope({
  envelope_id = "abc123-def456",
  include = "recipients,documents"
})

print("Subject: " .. result.emailSubject)
print("Status: " .. result.status)
```

---

## create_envelope

Create a new envelope for electronic signature.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `envelope_definition` | object | yes | Full envelope definition (see below) |

### Envelope Definition Fields

The `envelope_definition` object must contain:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `emailSubject` | string | yes | Email subject line |
| `documents` | array | yes* | Array of document objects (not needed if using templateId) |
| `templateId` | string | yes* | Template ID to create from (alternative to documents) |
| `recipients` | object | yes | Recipient roles: signers, ccs, etc. |
| `status` | string | no | `"sent"` to send immediately or `"created"` to save as draft (default: sent) |

### Examples

```lua
-- Create from a template
local result = app.integrations.docusign.create_envelope({
  envelope_definition = {
    templateId = "tmpl-abc123",
    emailSubject = "Please sign the NDA",
    status = "sent",
    templateRoles = {
      {
        roleName = "signer",
        name = "Jane Doe",
        email = "[email protected]"
      }
    }
  }
})

print("Envelope created: " .. result.envelopeId)
```

```lua
-- Create with inline documents
local result = app.integrations.docusign.create_envelope({
  envelope_definition = {
    emailSubject = "Contract for signature",
    status = "sent",
    documents = {
      {
        documentId = "1",
        name = "Contract.pdf",
        documentBase64 = "<base64-encoded PDF>"
      }
    },
    recipients = {
      signers = {
        {
          recipientId = "1",
          name = "John Smith",
          email = "[email protected]",
          tabs = {
            signHereTabs = {
              { documentId = "1", pageNumber = "1", xPosition = "100", yPosition = "500" }
            }
          }
        }
      }
    }
  }
})
```

---

## list_templates

List templates available in the DocuSign account.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `search_text` | string | no | Filter by name or description |
| `count` | integer | no | Number of results (default: 25) |
| `start_position` | integer | no | Zero-based pagination index |
| `folder_id` | string | no | Filter by folder ID |
| `order` | string | no | Sort direction: `"asc"` or `"desc"` |
| `order_by` | string | no | Sort field: `"name"` or `"modified"` |

### Example

```lua
local result = app.integrations.docusign.list_templates({
  search_text = "NDA",
  count = 10
})

for _, tmpl in ipairs(result.envelopeTemplates) do
  print(tmpl.templateId .. ": " .. tmpl.name)
end
```

---

## get_template

Get full details for a DocuSign template.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `template_id` | string | yes | The template ID |

### Example

```lua
local result = app.integrations.docusign.get_template({
  template_id = "tmpl-abc123"
})

print("Template: " .. result.name)
print("Documents: " .. #result.documents)
```

---

## list_documents

List documents attached to an envelope.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `envelope_id` | string | yes | The envelope ID |

### Example

```lua
local result = app.integrations.docusign.list_documents({
  envelope_id = "abc123-def456"
})

for _, doc in ipairs(result.envelopeDocuments) do
  print(doc.documentId .. ": " .. doc.name .. " (" .. doc.type .. ")")
end
```

---

## get_document

Download a document from an envelope.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `envelope_id` | string | yes | The envelope ID |
| `document_id` | string | yes | The document ID, or `"combined"` for all docs as one PDF |

### Example

```lua
local result = app.integrations.docusign.get_document({
  envelope_id = "abc123-def456",
  document_id = "1"
})

print("Size: " .. result.size_bytes .. " bytes")
-- result.content_base64 contains the base64-encoded document
```

---

## get_current_user

Get information about the authenticated DocuSign user.

### Parameters

None.

### Example

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

print("User: " .. result.name)
print("Email: " .. result.email)

for _, acct in ipairs(result.accounts) do
  print("Account: " .. acct.account_id .. " - " .. acct.account_name)
end
```

---

## Multi-Account Usage

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

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

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

-- Named accounts
app.integrations.docusign.production.function_name({...})
app.integrations.docusign.sandbox.function_name({...})
```

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

Metadata-Derived Lua Example

local result = app.integrations.docusign.docusign_list_envelopes({
  status = "example_status",
  from_date = "example_from_date",
  to_date = "example_to_date",
  search_text = "example_search_text",
  count = 1,
  start_position = 1,
  order = "example_order",
  order_by = "example_order_by"
})
print(result)

Functions

docusign_list_envelopes

List envelopes in the DocuSign account. Filter by status (sent, delivered, completed, signed, declined, voided), date range, or search text. Returns envelope summaries with IDs, subjects, statuses, and dates.

Operation
Read read
Full name
docusign.docusign_list_envelopes
ParameterTypeRequiredDescription
status string no Filter by status: sent, delivered, completed, signed, declined, voided, or "all" (default: all).
from_date string no Start date for filter (YYYY-MM-DD). Defaults to 30 days ago if not specified.
to_date string no End date for filter (YYYY-MM-DD). Defaults to today.
search_text string no Search envelope subjects and recipient names.
count integer no Number of results to return (default: 25, max: 100).
start_position integer no Zero-based index for pagination (default: 0).
order string no Sort direction: "asc" or "desc" (default: "desc").
order_by string no Sort field: "last_modified", "created", or "sent" (default: "last_modified").

docusign_get_envelope

Get detailed information about a DocuSign envelope including status, recipients, documents, and signing history. Use this to check if an envelope has been signed or to review its details.

Operation
Read read
Full name
docusign.docusign_get_envelope
ParameterTypeRequiredDescription
envelope_id string yes The envelope ID to retrieve.
include string no Comma-separated list of additional data to include: "recipients", "documents", "extensions", "custom_fields", "tabs".

docusign_create_envelope

Create a new DocuSign envelope for electronic signature. You can create from a template (pass template_id) or from scratch with inline documents and recipients. Set status to "sent" to send immediately or "created" to save as a draft.

Operation
Write write
Full name
docusign.docusign_create_envelope
ParameterTypeRequiredDescription
envelope_definition object yes The full envelope definition JSON object. Required fields: documents (or templateId), recipients (signers, cc, etc.), emailSubject, and status ("sent" or "created"). See DocuSign eSignature REST API docs for full schema.

docusign_list_templates

List templates available in the DocuSign account. Templates define reusable envelope structures with pre-configured documents, recipients, and signing tabs. Use a template ID to create envelopes from a template.

Operation
Read read
Full name
docusign.docusign_list_templates
ParameterTypeRequiredDescription
search_text string no Filter templates by name or description.
count integer no Number of results to return (default: 25).
start_position integer no Zero-based index for pagination (default: 0).
folder_id string no Filter by folder ID.
folder_ids array no Filter by multiple folder IDs.
order string no Sort direction: "asc" or "desc".
order_by string no Sort field: "name" or "modified".

docusign_get_template

Get details for a DocuSign template including its documents, recipient roles, signing tabs, and email settings. Use this to understand a template before creating an envelope from it.

Operation
Read read
Full name
docusign.docusign_get_template
ParameterTypeRequiredDescription
template_id string yes The template ID to retrieve.

docusign_list_documents

List documents in a DocuSign envelope. Returns document IDs, names, types (content or summary), and page counts. Use document IDs to download individual documents.

Operation
Read read
Full name
docusign.docusign_list_documents
ParameterTypeRequiredDescription
envelope_id string yes The envelope ID to list documents for.

docusign_get_document

Download a document from a DocuSign envelope. Returns the document content as base64-encoded data. Use "combined" as the document_id to download all documents as a single combined PDF.

Operation
Read read
Full name
docusign.docusign_get_document
ParameterTypeRequiredDescription
envelope_id string yes The envelope ID containing the document.
document_id string yes The document ID to download. Use "combined" to get all documents as a single PDF.

docusign_get_current_user

Get information about the authenticated DocuSign user, including name, email, and associated accounts. Useful for verifying credentials and discovering account IDs.

Operation
Read read
Full name
docusign.docusign_get_current_user
ParameterTypeRequiredDescription
No parameters.