Skip to main content

Get Chat Session by ID

Used to retrieve detailed information about a specific chat session, including all messages and conversation history. This endpoint provides complete conversation data with pagination support.

API Endpoint

PropertyValue
Request MethodPOST
Request URLhttps://api.seliseblocks.com/conversation/sessions/{session_id}

Request

Request Example

curl -X POST 'https://api.seliseblocks.com/conversation/sessions/session_abc123' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"widget_id": "widget_456",
"session_id": "session_abc123",
"agent_id": "agent_789",
"limit": 50,
"offset": 0,
"project_key": "YOUR_PROJECT_KEY"
}'

Path Parameters

FieldTypeRequiredDescription
session_idstringYesThe unique identifier of the chat session.

Request Headers

FieldTypeRequiredDescription
acceptstringYesAccepted response format. Use application/json
Content-Typeapplication/jsonYesData type, must be application/json.

Request Body

Request Body Schema

{
"widget_id": "string",
"session_id": "string",
"agent_id": "string",
"limit": 100,
"offset": 0,
"project_key": "string"
}

Request Body Parameters

FieldTypeRequiredDescription
widget_idstringYesThe unique identifier of the chat widget.
session_idstringYesThe session ID (should match path parameter).
agent_idstringYesThe unique identifier of the AI agent.
limitintegerNoMaximum number of messages to return per request (default: 100, max: 100).
offsetintegerNoNumber of messages to skip for pagination (default: 0).
project_keystringYesThe project key for your project.
tip

When to use this endpoint:

  • Conversation replay: Display full conversation history to users
  • Customer support: Review past interactions for context
  • Quality assurance: Audit specific conversations
  • Analytics: Analyze conversation flow and patterns
  • Debugging: Troubleshoot issues with specific sessions
  • Export: Extract conversation data for reporting or archival

Message pagination:

  • Messages are typically ordered chronologically (oldest to newest)
  • Use limit and offset to load conversations incrementally
  • Load initial messages with offset=0, then paginate for older messages
  • Implement "load more" or infinite scroll UI patterns
  • For long conversations, fetch messages in batches

Use cases:

  • Chat history UI: Display conversation in a scrollable interface
  • Transcript export: Generate PDF or text transcripts
  • Sentiment analysis: Analyze conversation tone and satisfaction
  • Training data: Extract conversations for model improvement
  • Compliance: Maintain records for legal or regulatory purposes
  • Context restoration: Restore conversation state after reconnection

Response

Success Response (200 OK)

Returns detailed session information with paginated message history.

{
"sessions": [
{
"_id": "64a1b2c3d4e5f6789012345",
"SessionId": "session_abc123",
"WidgetId": "widget_456",
"AgentId": "agent_789",
"CreatedAt": "2026-01-12T08:30:00Z",
"Query": "How do I reset my password?",
"QueryId": "query_001",
"Response": "I'll help you reset your password. You can do this by clicking the 'Forgot Password' link on the login page.",
"NextStepQuestions": [
"What should I do if I don't receive the reset email?",
"How long does the reset link stay valid?",
"Can I change my password from my account settings?"
],
"ResponseId": "response_001",
"Filters": {
"category": "account_support",
"priority": "medium"
},
"Metadata": {
"user_agent": "Mozilla/5.0...",
"ip_address": "192.168.1.1",
"referrer": "https://example.com/login"
},
"QueryTimestamp": "2026-01-12T08:30:15Z",
"ResponseTimestamp": "2026-01-12T08:30:18Z",
"ConversationType": "chat",
"UserId": "user_123",
"UserEmail": "john@example.com",
"UserRole": ["customer", "premium"],
"Summary": "User requested password reset assistance",
"Playground": false,
"IsPrivate": false,
"WorkflowName": "account_support_workflow",
"TokenUsage": "input: 120, output: 85, total: 205",
"WorkflowTrace": {
"steps": ["intent_classification", "knowledge_retrieval", "response_generation"],
"execution_time_ms": 450
},
"Error": null
},
{
"_id": "64a1b2c3d4e5f6789012346",
"SessionId": "session_abc123",
"WidgetId": "widget_456",
"AgentId": "agent_789",
"CreatedAt": "2026-01-12T08:31:00Z",
"Query": "I didn't receive the reset email",
"QueryId": "query_002",
"Response": "Let me check a few things. First, please verify that you entered the correct email address. Also, check your spam or junk folder.",
"NextStepQuestions": [
"What email address did you use?",
"Have you checked your spam folder?",
"When did you request the reset?"
],
"ResponseId": "response_002",
"Filters": {
"category": "account_support",
"priority": "high"
},
"Metadata": {
"follow_up": true,
"related_query_id": "query_001"
},
"QueryTimestamp": "2026-01-12T08:31:05Z",
"ResponseTimestamp": "2026-01-12T08:31:08Z",
"ConversationType": "chat",
"UserId": "user_123",
"UserEmail": "john@example.com",
"UserRole": ["customer", "premium"],
"Summary": "User reports not receiving password reset email",
"Playground": false,
"IsPrivate": false,
"WorkflowName": "account_support_workflow",
"TokenUsage": "input: 95, output: 120, total: 215",
"WorkflowTrace": {
"steps": ["context_retrieval", "troubleshooting", "response_generation"],
"execution_time_ms": 380
},
"Error": null
}
],
"total_count": 15
}

Response Fields

FieldTypeDescription
sessionsarrayArray of message objects representing the conversation history.
total_countintegerTotal number of messages in the session (for pagination).
note

Message Object Structure

Each message object in the sessions array contains:

Identifiers:

  • _id: MongoDB object ID for the message
  • SessionId: Session identifier
  • WidgetId: Widget used for the conversation
  • AgentId: AI agent handling the conversation
  • QueryId: Unique identifier for the user query
  • ResponseId: Unique identifier for the agent response

Conversation Content:

  • Query: User's message/question
  • Response: Agent's reply
  • NextStepQuestions: Suggested follow-up questions for the user
  • Summary: Brief summary of the message exchange

Timestamps:

  • CreatedAt: Message creation timestamp (ISO 8601)
  • QueryTimestamp: When user sent the query
  • ResponseTimestamp: When agent responded

Categorization:

  • ConversationType: Type of conversation (chat, voice, email, etc.)
  • Filters: Message categorization and routing filters
  • Metadata: Additional contextual information

User Information:

  • UserId: User identifier
  • UserEmail: User's email address
  • UserRole: Array of user roles or permissions

Workflow and Performance:

  • WorkflowName: Name of the workflow that processed the message
  • TokenUsage: AI model token consumption statistics
  • WorkflowTrace: Detailed execution trace for debugging
  • Error: Error message if processing failed (null if successful)

Privacy and Settings:

  • Playground: Whether this is a test/playground conversation
  • IsPrivate: Privacy flag for sensitive conversations

Error Response (422 Unprocessable Entity)

Returns validation error details when request parameters are invalid or session not found.

{
"detail": [
{
"loc": [
"path",
"session_id"
],
"msg": "Session not found or access denied",
"type": "value_error.notfound"
}
]
}

Error Response Fields

FieldTypeDescription
detailarrayArray of validation error objects.
locarrayLocation of the error in the request (e.g., path, body field).
msgstringHuman-readable error message.
typestringError type identifier.

Common Error Scenarios

Error TypeDescriptionResolution
Session Not FoundThe specified session_id doesn't existVerify session_id is correct
Access DeniedInsufficient permissions to view sessionCheck API credentials and permissions
Mismatched IDsPath session_id doesn't match body session_idEnsure both session_id values are identical
Invalid AgentAgent_id doesn't match session's agentUse correct agent_id for the session
Invalid WidgetWidget_id doesn't match session's widgetUse correct widget_id for the session
Invalid Project KeyProject key is incorrectVerify project_key credentials
Invalid PaginationLimit or offset values out of rangeEnsure limit ≤ 100 and offset ≥ 0

Error Codes

Status CodeDescriptionResponse Type
200OK - Session retrieved successfullySuccess
400Bad Request - Invalid request formatBad Request
401Unauthorized - Authentication requiredUnauthorized
403Forbidden - Access denied to sessionForbidden
404Not Found - Session doesn't existNot Found
422Validation Error - Invalid parametersUnprocessable Entity
500Internal Server Error - Failed to fetch sessionInternal Server Error
warning

Important Considerations

  • Data privacy: Session data may contain sensitive user information; handle securely
  • GDPR compliance: Respect user data deletion and export requests
  • Performance: Large conversations may require multiple paginated requests
  • Real-time updates: Messages may be added during retrieval; implement refresh logic
  • Token usage: Review TokenUsage field to monitor AI costs per message
  • Error handling: Check Error field to identify failed message processing
  • Caching: Cache session data appropriately to reduce API load
  • Message order: Messages are typically chronological; verify order in your UI
  • Metadata: Extract custom metadata for analytics and reporting
  • Workflow traces: Use WorkflowTrace for debugging complex agent behaviors
  • Next step questions: Implement suggested questions for better UX
  • Rate limiting: Avoid excessive session detail requests