Tickets API

This section documents all ticket-related API methods.

createTicket(title, description, priority, category)

Creates a new support ticket.

Parameters:

Returns: Promise<Ticket>

Example:

const ticket = await API.createTicket(
    'Login not working',
    'Cannot access my account since yesterday. Error: Invalid credentials.',
    'high',
    'technical'
);
console.log('Ticket created:', ticket.id);

getTicket(id)

Retrieves a single ticket by ID.

Parameters:

Name

Type

Description

id

number

Ticket ID

Returns: Promise<Ticket|null>

Example:

const ticket = await API.getTicket(123);
if (ticket) {
    console.log('Title:', ticket.title);
    console.log('Status:', ticket.status);
}

closeTicket(id, response)

Closes an open ticket with an administrator response.

Parameters:

Returns: Promise<boolean>

Example:

const success = await API.closeTicket(
    123,
    'Issue resolved by password reset. Please check your email.'
);
if (success) {
    console.log('Ticket resolved');
}

addComment(ticketId, text, authorEmail, authorName)

Adds a comment to a ticket.

Parameters:

Name

Type

Description

ticketId

number

Target ticket ID

text

string

Comment content

authorEmail

string

Comment author’s email

authorName

string

Comment author’s name

Returns: Promise<boolean>

Example:

await API.addComment(
    123,
    'Thank you for the update!',
    'user@example.com',
    'John User'
);

assignTicket(ticketId, adminEmail)

Assigns a ticket to an administrator (admin only).

Parameters:

Returns: Promise<boolean>

Example:

const admins = API.getAdmins();
await API.assignTicket(123, admins[0].email);

Query Methods

getOpenTickets()

Returns all open tickets sorted by creation date.

Returns: Promise<Ticket[]>

getClosedTickets()

Returns all closed tickets sorted by creation date (newest first).

Returns: Promise<Ticket[]>

getUserOpenTickets(email)

Returns open tickets for a specific user.

Returns: Promise<Ticket[]>

getUserClosedTickets(email)

Returns closed tickets for a specific user.

Returns: Promise<Ticket[]>

getStats()

Returns global statistics.

Returns: Promise<Stats>

const stats = await API.getStats();
console.log('Open:', stats.openCount);
console.log('Closed:', stats.closedCount);
console.log('Total:', stats.totalCount);

searchTickets(tickets, query)

Filters tickets by title or ID.

Parameters:

Name

Type

Description

tickets

Ticket[]

Array of tickets to filter

query

string

Search query

Returns: Ticket[]

Ticket Object Schema

interface Ticket {
    id: number;
    title: string;
    description: string;
    userEmail: string;
    priority: 'urgent' | 'high' | 'normal' | 'low';
    category: 'general' | 'technical' | 'billing' |
              'suggestion' | 'bug' | 'other';
    status: 'open' | 'closed';
    createdAt: number;
    response?: string;
    responseAt?: number;
    assignedTo?: string;
    assignedAt?: number;
    comments: Comment[];
}

interface Comment {
    text: string;
    authorEmail: string;
    authorName: string;
    createdAt: number;
}

Priority Levels

Categories