Chat API

Chat threads represent conversations between users, while messages are individual communications within those threads.

Endpoints

Method Endpoint Description
GET /chat/threads List chat threads
POST /chat/threads Create a new chat thread
GET /chat/threads/{thread_id} Get a specific chat thread
POST /chat/threads/{thread_id}/messages Add a message to a chat thread
PATCH /chat/threads/{thread_id}/messages/{message_id} Update a message in a chat thread
GET /chat/threads/{thread_id}/participants Get participants of a chat thread
POST /chat/threads/{thread_id}/participants Add a participant to a chat thread

Thread Attributes

Attribute Type Description
id integer The ID of the chat thread
created_by_id integer The ID of the user who created the thread
created_at string The date and time when the thread was created (ISO 8601)
last_message_created_at string The date and time of the most recent message in the thread (ISO 8601, read-only)
client_account_id integer The client account ID associated with the thread
provider_client_account_id integer The provider client account ID associated with the thread
subject string The subject line of the thread
relation_type string The type of entity the thread is associated with (e.g. document, businesspartner)
relation_id integer The ID of the related entity
is_completed boolean Whether the thread is marked as completed
is_archived boolean Whether the thread is archived

Message Attributes

Attribute Type Description
id integer The ID of the message
thread_id integer The ID of the chat thread associated with the message
from_user_id integer The ID of the user who sent the message
message string The content of the message. Code blocks are obscured (see Code Blocks in Messages)
is_draft boolean Whether the message is a draft
created_at string The date and time when the message was created (ISO 8601)
created_by_id integer The ID of the user who created the message
action_items array List of preview objects extracted from coderesult blocks
action_mode string The execution mode from coderesult blocks (preview or write), or null
action_error boolean true if the coderesult block reported an execution error

Code Blocks in Messages

Messages can contain special code blocks that are processed by the system:

Block Type Description
codeaction Executable code blocks that perform actions. Initially run in preview mode. If no approval is needed, automatically run in write mode.
approvecodeaction Approval blocks that trigger write-mode execution of the previous codeaction block. The result is posted as a new message.
coderesult Result blocks containing execution output and preview objects. Generated automatically after processing codeaction blocks.

Code Block Processing

  1. codeaction blocks:
    • First run in preview mode
    • If no errors and no objects need approval, automatically run in write mode
    • A coderesult block is added after the codeaction block
    • Results are posted as a new message
  2. approvecodeaction blocks:
    • Finds the last codeaction block in the thread
    • Runs that block in write mode (is_approved=true)
    • Posts the result as a new message containing only the coderesult block

API Response Format

When retrieving messages, code blocks are handled securely:

  • Code content in codeaction and coderesult blocks is hidden with “[code hidden]”
  • Preview objects from coderesult blocks are extracted into structured data
  • The execution mode is included when available

Example response for a message with processed code blocks:

{
    "id": 123,
    "message": "Let's process this:\n```codeaction\n[code hidden]\n```\n```coderesult\n[code hidden]\n```",
    "action_items": [
        {
            "type": "preview",
            "needs_approval": true,
            "id": 1
        }
    ],
    "action_mode": "preview"
}

Example of an approval message:

{
    "id": 124,
    "message": "```approvecodeaction\n```",
    "action_items": [],
    "action_mode": null
}

Example of the result message after approval:

{
    "id": 125,
    "message": "```coderesult\n[code hidden]\n```",
    "action_items": [
        {
            "type": "preview",
            "needs_approval": false,
            "id": 1
        }
    ],
    "action_mode": "write"
}

Participant Attributes

Attribute Type Description
id integer The ID of the participant
thread_id integer The ID of the chat thread associated with the participant
user_id integer The ID of the user associated with the participant
created_by_id integer The ID of the user who added this participant
created_at string The date and time when the participant was added (ISO 8601)

Query Parameters

The GET /chat/threads endpoint accepts the following query parameters. All filters are optional. When client_account_id is omitted, threads are returned across all of the user’s eligible client accounts.

Parameter Type Description
client_account_id integer Filter threads by client account ID
provider_client_account_id integer Filter threads by provider client account ID
relation_type string Filter threads by relation type (e.g. document, businesspartner)
relation_id integer Filter threads by relation ID
free_text string Search threads by subject or message content
order_by string Sort field (e.g. created_at, -last_message_created_at)
page integer The page number for paginated results (default: 1)
per_page integer The number of items per page (default: 100)

Search Examples

Search threads by text content:

GET /api/v2/chat/threads?free_text=invoice

This will return threads where either:

  • The thread subject contains “invoice”
  • Any message in the thread contains “invoice”

The search is case-insensitive and matches partial words. You can combine search with other filters:

GET /api/v2/chat/threads?free_text=invoice&client_account_id=123&relation_type=document

Relationships

Relationship Type Description
messages [Message] The messages in a chat thread
participants [Participant] The participants in a chat thread

Notes

  • All endpoints require authentication.
  • All filter parameters on GET /chat/threads are optional. Use free_text only when you need full-text search across thread subjects and messages.
  • Access to threads and messages is restricted based on the user’s eligible client accounts. Access is granted if the user can access either the thread’s client_account_id or its provider_client_account_id.
  • Error responses:
    • 403 Forbidden: When trying to access a thread the user is not associated with.
    • 404 Not Found: When a specified thread or message doesn’t exist.