Export API
The Export API provides data export functionality for GDPR compliance (data portability), backups, and analytics exports. Supports CSV, JSON, and PDF formats.
Export Response Object
{
format: 'csv' | 'json' | 'pdf';
data: string | object[]; // CSV string, JSON array, or base64 PDF
count: number; // Number of records exported
exportedAt: string; // ISO timestamp
filename?: string; // Suggested filename (PDF only)
}
Export Tickets
Export tickets with optional filtering. Admin only.
Procedure: export.tickets
Authentication: Required (Admin)
Input:
{
format?: 'csv' | 'json' | 'pdf'; // Default: 'csv'
status?: string; // Filter by status
startDate?: string; // ISO datetime, filter by created_at >=
endDate?: string; // ISO datetime, filter by created_at <=
limit?: number; // 1-10000, default: 1000
}
Example:
curl -X GET "https://your-domain.com/api/trpc/export.tickets?input=%7B%22format%22:%22csv%22,%22status%22:%22resolved%22,%22limit%22:500%7D" \
-H "Cookie: your-session-cookie"
Response (CSV):
{
"result": {
"data": {
"json": {
"format": "csv",
"data": "id,number,subject,status,priority,...\nuuid,1234,Help with order,resolved,normal,...",
"count": 500,
"exportedAt": "2024-01-15T10:30:00.000Z"
}
}
}
}
Response (JSON):
{
"result": {
"data": {
"json": {
"format": "json",
"data": [
{
"id": "uuid",
"number": 1234,
"subject": "Help with order",
"status": "resolved",
"priority": "normal",
"requester_name": "John Doe",
"requester_email": "john@example.com",
"assignee_name": "Agent Smith",
"assignee_email": "agent@example.com",
"tags": "billing; refund",
"created_at": "2024-01-10T09:00:00.000Z",
"resolved_at": "2024-01-10T11:30:00.000Z"
}
],
"count": 500,
"exportedAt": "2024-01-15T10:30:00.000Z"
}
}
}
}
Exported Ticket Fields
| Field | Description |
|---|---|
id | Ticket UUID |
number | Ticket number |
subject | Ticket subject |
status | Current status |
priority | Priority level |
type | Ticket type |
summary | AI-generated summary |
requester_name | Requester's name |
requester_email | Requester's email |
assignee_name | Assignee's name |
assignee_email | Assignee's email |
tags | Tags (semicolon-separated) |
created_at | Creation timestamp |
updated_at | Last update timestamp |
resolved_at | Resolution timestamp |
Export Customers
Export customer data. Admin only.
Procedure: export.customers
Authentication: Required (Admin)
Input:
{
format?: 'csv' | 'json' | 'pdf'; // Default: 'csv'
limit?: number; // 1-10000, default: 1000
}
Example:
curl -X GET "https://your-domain.com/api/trpc/export.customers?input=%7B%22format%22:%22json%22%7D" \
-H "Cookie: your-session-cookie"
Response:
{
"result": {
"data": {
"json": {
"format": "json",
"data": [
{
"id": "uuid",
"name": "John Doe",
"email": "john@example.com",
"phone": "+1234567890",
"created_at": "2024-01-01T00:00:00.000Z",
"updated_at": "2024-01-15T10:00:00.000Z"
}
],
"count": 250,
"exportedAt": "2024-01-15T10:30:00.000Z"
}
}
}
}
Export Analytics
Export analytics events. Admin only.
Procedure: export.analytics
Authentication: Required (Admin)
Input:
{
format?: 'csv' | 'json'; // Default: 'csv' (no PDF)
startDate?: string; // ISO datetime
endDate?: string; // ISO datetime
limit?: number; // 1-10000, default: 1000
}
Example:
curl -X GET "https://your-domain.com/api/trpc/export.analytics?input=%7B%22startDate%22:%222024-01-01T00:00:00Z%22%7D" \
-H "Cookie: your-session-cookie"
Response:
{
"result": {
"data": {
"json": {
"format": "csv",
"data": "event_name,user_id,properties,created_at\nticket_created,uuid,{},2024-01-15T10:00:00.000Z",
"count": 1000,
"exportedAt": "2024-01-15T10:30:00.000Z"
}
}
}
}
GDPR User Data Export
Export all data associated with a specific user for GDPR data portability compliance.
Procedure: export.gdprUserData
Authentication: Required
Input:
{
userId?: string; // UUID (optional, defaults to requesting user)
}
Permissions:
- Users can export their own data
- Admins can export any user's data
Example:
curl -X GET "https://your-domain.com/api/trpc/export.gdprUserData?input=%7B%22userId%22:%22user-uuid%22%7D" \
-H "Cookie: your-session-cookie"
Response:
{
"result": {
"data": {
"json": {
"exportedAt": "2024-01-15T10:30:00.000Z",
"userId": "user-uuid",
"profile": {
"id": "user-uuid",
"email": "john@example.com",
"name": "John Doe",
"role": "agent",
"preferences": {},
"created_at": "2024-01-01T00:00:00.000Z",
"updated_at": "2024-01-15T10:00:00.000Z"
},
"tickets": [
{
"id": "ticket-uuid",
"number": 1234,
"subject": "Help request",
"status": "resolved",
"priority": "normal",
"created_at": "2024-01-10T09:00:00.000Z"
}
],
"conversations": [
{
"id": "conv-uuid",
"content_text": "Thank you for your help...",
"created_at": "2024-01-10T10:00:00.000Z"
}
],
"notifications": [
{
"id": "notif-uuid",
"title": "Ticket Assigned",
"message": "You've been assigned...",
"type": "ticketAssigned",
"read": true,
"created_at": "2024-01-10T09:30:00.000Z"
}
],
"analyticsEvents": [
{
"event_name": "ticket_viewed",
"properties": { "ticketId": "uuid" },
"created_at": "2024-01-10T09:15:00.000Z"
}
],
"metadata": {
"totalTickets": 15,
"totalConversations": 42,
"totalNotifications": 100,
"totalEvents": 250
}
}
}
}
}
Export Ticket Conversations
Export all conversations for a specific ticket.
Procedure: export.ticketConversations
Authentication: Required
Input:
{
ticketId: string; // Ticket UUID
format?: 'csv' | 'json'; // Default: 'json'
}
Example:
curl -X GET "https://your-domain.com/api/trpc/export.ticketConversations?input=%7B%22ticketId%22:%22ticket-uuid%22%7D" \
-H "Cookie: your-session-cookie"
Response:
{
"result": {
"data": {
"json": {
"format": "json",
"ticket": {
"id": "ticket-uuid",
"number": 1234,
"subject": "Help with billing"
},
"conversations": [
{
"id": "conv-uuid",
"author_name": "John Doe",
"author_email": "john@example.com",
"content": "I need help with my bill...",
"internal": "No",
"channel": "email",
"created_at": "2024-01-10T09:00:00.000Z"
},
{
"id": "conv-uuid-2",
"author_name": "Agent Smith",
"author_email": "agent@example.com",
"content": "Hi John, I'd be happy to help...",
"internal": "No",
"channel": "web",
"created_at": "2024-01-10T09:30:00.000Z"
}
],
"count": 2,
"exportedAt": "2024-01-15T10:30:00.000Z"
}
}
}
}
PDF Exports
PDF exports include formatted headers with organization name and export date.
Example PDF response:
{
"format": "pdf",
"data": "data:application/pdf;base64,JVBERi0xLjQK...",
"count": 100,
"exportedAt": "2024-01-15T10:30:00.000Z",
"filename": "tickets-export-2024-01-15.pdf"
}
To download the PDF:
// Decode base64 and create download link
const pdfData = response.data
const link = document.createElement('a')
link.href = pdfData
link.download = response.filename
link.click()
Error Codes
| Code | Description |
|---|---|
FORBIDDEN | Only admins can export data (except own GDPR data) |
NOT_FOUND | Ticket not found |
BAD_REQUEST | Invalid date format or parameters |