Create Ticket
Create a new support ticket
Creates a new support ticket with specified details.
Endpoint
POST https://api.ayra.ai/v1/ticketsAuthentication
Requires API key with tickets:write permission.
Request Parameters
Required Parameters:
subject(string) - Brief ticket summary. Maximum 200 characters.description(string) - Detailed issue description. Maximum 10,000 characters. Supports Markdown.Optional Parameters:
priority(integer) - Ticket priority level. Values: 1 (Critical), 2 (High), 3 (Normal), 4 (Low). Default: 3status(string) - Initial status. Values: new, open, in_progress. Default: newcategory(string) - Issue category. Examples: technical, billing, account, product, bug, feature_requestcontact_id(string) - Associated customer contact IDconversation_id(string) - Conversation that generated this ticketassigned_to(string) - User ID to assign ticket todue_date(string) - ISO 8601 timestamp when ticket is duetags(array of strings) - Descriptive tags for organizationcustom_fields(object) - Custom key-value datametadata(object) - Additional metadataRequest Example
curl -X POST https://api.ayra.ai/v1/tickets \
-H "Authorization: Bearer sk_live_abc123xyz789" \
-H "Content-Type: application/json" \
-d '{
"subject": "Duplicate billing charge needs refund",
"description": "Customer was charged twice for order #12345...",
"priority": 2,
"category": "billing",
"contact_id": "contact_xyz789",
"conversation_id": "conv_abc123xyz789",
"assigned_to": "user_billing_specialist",
"tags": ["refund", "duplicate_charge", "urgent"],
"due_date": "2025-01-16T17:00:00Z"
}'JavaScript Example
async function createTicket(ticketData) {
try {
const response = await axios.post(
'https://api.ayra.ai/v1/tickets',
ticketData,
{
headers: {
'Authorization': 'Bearer sk_live_abc123xyz789',
'Content-Type': 'application/json'
}
}
);
console.log('Ticket created:', response.data.data.id);
return response.data;
} catch (error) {
console.error('Error creating ticket:', error.response.data);
throw error;
}
}
// Example: Create ticket from conversation
async function createTicketFromConversation(conversation) {
const ticketData = {
subject: `Issue from call: ${conversation.summary}`,
description: `**Conversation Summary:**\n${conversation.summary}`,
priority: conversation.sentiment === 'negative' ? 2 : 3,
category: conversation.topics[0]?.name || 'general',
contact_id: conversation.contact_id,
conversation_id: conversation.id,
tags: conversation.topics.map(t => t.name)
};
return createTicket(ticketData);
}Python Example
def create_ticket(subject, description, **kwargs):
url = 'https://api.ayra.ai/v1/tickets'
headers = {
'Authorization': 'Bearer sk_live_abc123xyz789',
'Content-Type': 'application/json'
}
data = {
'subject': subject,
'description': description,
**kwargs
}
response = requests.post(url, json=data, headers=headers)
if response.status_code == 201:
ticket = response.json()
print(f"Ticket created: {ticket['data']['id']}")
return ticket
else:
print('Error:', response.json())
raise Exception(f'Failed to create ticket: {response.status_code}')
# Example: Create high priority ticket
ticket = create_ticket(
subject='System outage - Customer portal down',
description='Multiple customers reporting inability to access...',
priority=1,
category='technical',
status='open',
assigned_to='user_engineering_oncall',
tags=['outage', 'portal', 'critical']
)Response
Success Response (201 Created):
{
"data": {
"id": "ticket_abc123xyz789",
"number": "TICK-1234",
"subject": "Duplicate billing charge needs refund",
"priority": 2,
"priority_label": "High",
"status": "new",
"category": "billing",
"contact_id": "contact_xyz789",
"conversation_id": "conv_abc123xyz789",
"assigned_to": "user_billing_specialist",
"tags": ["refund", "duplicate_charge", "urgent"],
"due_date": "2025-01-16T17:00:00Z",
"sla": {
"response_deadline": "2025-01-15T18:30:00Z",
"resolution_deadline": "2025-01-16T17:00:00Z"
},
"created_at": "2025-01-15T14:30:00Z"
}
}Error Responses
400 Bad Request - Missing Required Field:
{
"error": {
"type": "invalid_request",
"message": "The 'subject' field is required",
"code": "missing_required_field",
"field": "subject"
}
}Notes
- •Ticket numbers are automatically generated in format TICK-#### and are unique
- •SLA deadlines are automatically calculated based on priority and business hours
- •Tickets can be created without contacts for internal issues
- •Description supports Markdown for rich formatting
- •Creating tickets triggers webhook events if configured
Ready to transform your agency?
Start building with Ayra today. No credit card required.