Skip to content

Fetch Conversations

The fetch_conversations() method allows you to retrieve a paginated list of conversations with powerful filtering options. Use it to build dashboards, query specific conversations, or export data.

Method Signature

python
agentsight_api.fetch_conversations(
    page: Optional[int] = None,
    page_size: Optional[int] = None,
    conversation_id: Optional[str] = None,
    customer_id: Optional[str] = None,
    name: Optional[str] = None,
    device: Optional[str] = None,
    language: Optional[str] = None,
    customer_ip_address: Optional[str] = None,
    is_marked: Optional[bool] = None,
    include_deleted: Optional[bool] = None,
    started_at_after: Optional[Union[str, datetime]] = None,
    started_at_before: Optional[Union[str, datetime]] = None,
    has_messages: Optional[bool] = None,
    message_contains: Optional[str] = None,
    action_name: Optional[str] = None,
    has_feedback: Optional[bool] = None,
    feedback_sentiment: Optional[str] = None,
    feedback_source: Optional[str] = None,
    metadata: Optional[str] = None,
    **extra_params
)

Parameters

ParameterTypeDescription
pageintegerPage number (default: 1)
page_sizeintegerResults per page (default: 10, max: 100)
conversation_idstringExact match for conversation ID
customer_idstringExact match for customer ID
namestringSearch in conversation name (case-insensitive)
devicestringFilter by device type
languagestringFilter by language code
customer_ip_addressstringExact match for customer IP
is_markedbooleanFilter by favorite status
include_deletedbooleanInclude soft-deleted conversations
started_at_afterdatetime/stringConversations started after timestamp
started_at_beforedatetime/stringConversations started before timestamp
has_messagesbooleanOnly conversations with messages
message_containsstringSearch within message contents
action_namestringFilter by action name
has_feedbackbooleanOnly conversations with feedback
feedback_sentimentstringFilter by sentiment: positive, neutral, negative
feedback_sourcestringFilter by source: customer, platform
metadatastringFilter by metadata (format: key:value,key2:value2)

Usage Example

python
from agentsight import agentsight_api
from datetime import datetime, timedelta

# Fetch conversations with multiple filters
conversations = agentsight_api.fetch_conversations(
    feedback_sentiment="positive",
    feedback_source="customer",
    device="mobile",
    has_messages=True,
    started_at_after=(datetime.now() - timedelta(days=7)).isoformat(),
    page=1,
    page_size=20
)

# Process results
for conv in conversations['results']:
    print(f"Conversation: {conv['name']}")
    print(f"  Customer: {conv['customer_id']}")
    print(f"  Device: {conv['device']}")
    print(f"  Messages: {len(conv['messages'])}")
    print(f"  Feedbacks: {len(conv['feedbacks'])}")

Filtering Examples

By Customer

python
# Specific customer
conversations = agentsight_api.fetch_conversations(
    customer_id="user-456"
)

# Partial customer ID match
conversations = agentsight_api.fetch_conversations(
    customer_id__icontains="premium"
)

By Time Range

python
from datetime import datetime, timedelta

# Last 24 hours
yesterday = datetime.now() - timedelta(days=1)
conversations = agentsight_api.fetch_conversations(
    started_at_after=yesterday.isoformat()
)

# Specific date range
conversations = agentsight_api.fetch_conversations(
    started_at_after="2024-01-01T00:00:00Z",
    started_at_before="2024-01-31T23:59:59Z"
)

# Last 7 days
week_ago = datetime.now() - timedelta(days=7)
conversations = agentsight_api.fetch_conversations(
    started_at_after=week_ago.isoformat()
)

By Device and Language

python
# Mobile conversations in English
conversations = agentsight_api.fetch_conversations(
    device="mobile",
    language="en"
)

# Desktop conversations
conversations = agentsight_api.fetch_conversations(
    device="desktop"
)

By Feedback

python
# Positive customer feedback
conversations = agentsight_api.fetch_conversations(
    feedback_sentiment="positive",
    feedback_source="customer"
)

# Negative feedback needing review
conversations = agentsight_api.fetch_conversations(
    feedback_sentiment="negative",
    is_marked=True
)

# Conversations without feedback
conversations = agentsight_api.fetch_conversations(
    has_feedback=False
)

By Message Content

python
# Search for specific keywords
conversations = agentsight_api.fetch_conversations(
    message_contains="password reset"
)

# Find technical support conversations
conversations = agentsight_api.fetch_conversations(
    message_contains="error",
    action_name="database_query"
)

By Actions

python
# Conversations with specific action
conversations = agentsight_api.fetch_conversations(
    action_name="database_lookup"
)

# Conversations with API calls
conversations = agentsight_api.fetch_conversations(
    action_name="api_call"
)

By Metadata

python
# Single metadata filter
conversations = agentsight_api.fetch_conversations(
    metadata="priority:high"
)

# Multiple metadata filters
conversations = agentsight_api.fetch_conversations(
    metadata="status:resolved,customer_tier:premium"
)

# Nested metadata
conversations = agentsight_api.fetch_conversations(
    metadata="analysis.sentiment:positive"
)

Marked/Favorite Conversations

python
# Only marked conversations
conversations = agentsight_api.fetch_conversations(
    is_marked=True
)

# Unmarked conversations
conversations = agentsight_api.fetch_conversations(
    is_marked=False
)

Include Deleted

python
# Include soft-deleted conversations
conversations = agentsight_api.fetch_conversations(
    include_deleted=True
)

# Filter to only deleted
all_convs = agentsight_api.fetch_conversations(include_deleted=True)
deleted_convs = [c for c in all_convs['results'] if c['is_deleted']]

Combining Filters

python
# Complex query: VIP customers with positive feedback
conversations = agentsight_api.fetch_conversations(
    metadata="customer_tier:vip",
    feedback_sentiment="positive",
    device="desktop",
    has_messages=True,
    is_marked=True,
    page_size=50
)

# Support tickets needing review
conversations = agentsight_api.fetch_conversations(
    feedback_sentiment="negative",
    is_marked=True,
    metadata="status:pending",
    started_at_after="2024-01-01T00:00:00Z"
)

Pagination

python
# Get specific page
conversations = agentsight_api.fetch_conversations(
    page=2,
    page_size=25
)

Response Structure

python
response = agentsight_api.fetch_conversations(page_size=2)

# Response structure:
{
    "count": 245,  # Total matching conversations
    "next": "https://api.agentsight.io/api/conversations/?page=2",
    "previous": None,
    "results": [
        {
            "id": 42,
            "conversation_id": "conv-abc-123",
            "name": "Support Chat",
            "customer_id": "user-456",
            "customer_ip_address": "203.0.113.45",
            "device": "desktop",
            "language": "en",
            "environment": "production",
            "is_marked": True,
            "is_deleted": False,
            "started_at": "2024-01-15T10:30:00Z",
            "ended_at": "2024-01-15T10:35:00Z",
            "metadata": {...},
            "geo_location": {...},
            "messages": [...],
            "feedbacks": [...]
        }
    ]
}