Options
All
  • Public
  • Public/Protected
  • All
Menu

Class tickets

TicketService includes methods that work with tickets. Tickets represent a visitor that is currently in the queue.

For example, to create a new ticket, use create.

import * as Qminder from 'qminder-api';
Qminder.setKey('API_KEY_HERE');

// Example 1. Create a new ticket in Line ID 12346
const ticket = await Qminder.tickets.create(12346, {
   firstName: 'Jane',
   lastName: 'Eyre',
   phoneNumber: 13185551234
});

For example, to get a list of all visitors currently in the queue, use search.

import * as Qminder from 'qminder-api';
Qminder.setKey('API_KEY_HERE');

// Example 2. Get a list of all visitors currently in queue in location 12345
const visitors = await Qminder.tickets.search({ location: 12345, status: ['NEW'] });

This service additionally includes methods to work with visitors, such as call them to service, add custom business-specific labels or mark them as served.

For example, to call the next visitor in the lines 12345, 12346 and 12347, use {@link callNext}.

import * as Qminder from 'qminder-api';
Qminder.setKey('API_KEY_HERE');

// Example 3. Call the next visitor in lines 12345, 12346, 12347
const visitor = await Qminder.tickets.callNext([12345, 12346, 12347]);
console.log(visitor);
// => { id: 141592145 }

Hierarchy

  • tickets

Index

Constructors

constructor

Methods

Static addLabel

  • addLabel(ticket: IdOrObject<Ticket>, label: string, user?: IdOrObject<User>): Promise<"success" | "no action">
  • Add a label to a ticket.

    It adds a label to the ticket's labels list. Clerks can see the labels in the Service View, and can save additional details about the visitor into the label list. Labels are automatically colored.

    For example:

    import * as Qminder from 'qminder-api';
    Qminder.setKey('API_KEY_HERE');
    
    const myUserId = 15151;
    const ticket = 591050;
    const labelText = "Has documents";
    await Qminder.tickets.addLabel(ticket, labelText, myUserId);
    

    Parameters

    • ticket: IdOrObject<Ticket>

      The ticket to label. The ticket ID can be used instead of the Ticket object.

    • label: string

      The label to add, eg. "Has documents"

    • Optional user: IdOrObject<User>

      The user that is adding the label.

    Returns Promise<"success" | "no action">

    promise that resolves to 'success' if all was OK, and 'no action' if the label was already there, and rejects if something else went wrong.

Static assignToUser

  • assignToUser(ticket: IdOrObject<Ticket>, assigner: IdOrObject<User>, assignee: IdOrObject<User>): Promise<"success">
  • Assign the given ticket to an user (assignee).

    The user who is assigning (assigner) should be the second argument. The user who will take the ticket (assignee) should be the third argument.

    For example:

    import * as Qminder from 'qminder-api';
    Qminder.setKey('API_KEY_HERE');
    
    // Example 1. Assign Ticket 11425 to User 12345, and the user performing the action is 91020.
    const myUserId = 91020;
    const ticketId = 11425;
    const assigneeId = 12345;
    await Qminder.tickets.assignToUser(ticketId, myUserId, assigneeId);
    console.log('It worked!');
    
    // Example 2. Assign all tickets in Line 111 to user 15152
    const tickets: Array<Ticket> = await Qminder.tickets.search({ line: 111, status: ['NEW'] });
    tickets.map((ticket: Ticket) => Qminder.tickets.assign(ticket, 15152));
    

    Parameters

    • ticket: IdOrObject<Ticket>

      The ticket to assign to an user. The ticket ID can be used instead of the Ticket object.

    • assigner: IdOrObject<User>

      The user who is assigning.

    • assignee: IdOrObject<User>

      The user who will take the ticket.

    Returns Promise<"success">

    resolves to 'success' on success

Static call

  • call(ticket: IdOrObject<Ticket>, user?: IdOrObject<Ticket>, desk?: IdOrObject<Ticket>, keepActiveTicketsOpen?: boolean): Promise<Ticket>
  • Call a specific ticket to service.

    Calling a ticket will notify the visitor via all available channels, show the visitor details to the clerk on the Service View, and change the ticket status to 'CALLED'.

    Only tickets that are waiting (their status is 'NEW') can be called.

    By default, allows only one ticket to be in the 'CALLED' state, and marks other 'CALLED' tickets as served.

    Multiple tickets can be called by setting keepActiveTicketsOpen to true.

    Parameters

    • ticket: IdOrObject<Ticket>

      The ticket to call. The ticket ID can be used instead of the Ticket object.

    • Optional user: IdOrObject<Ticket>

      the user that is calling the ticket. This parameter is not needed if Qminder.setKey was called with an API key belonging to a specific User. The user ID can be used instead of the User object.

    • Optional desk: IdOrObject<Ticket>

      the desk to call the ticket into. The desk ID can be used instead of the Desk object.

    • Optional keepActiveTicketsOpen: boolean

      if tickets are currently being served, do not mark them served when calling a new ticket. This allows calling multiple tickets at the same time.

    Returns Promise<Ticket>

    the ticket that was just called

Static cancel

  • cancel(ticket: IdOrObject<Ticket>, user: IdOrObject<User>): Promise<string>
  • Cancel a ticket.

    Cancelling a ticket removes them from the queue, and from statistics.

    Only new tickets (with the status 'NEW') can be cancelled.

    The user ID is mandatory.

    Parameters

    • ticket: IdOrObject<Ticket>

      The ticket to cancel. The ticket ID can be used instead of the Ticket object.

    • user: IdOrObject<User>

      The user who canceled the ticket. This is a mandatory argument.

    Returns Promise<string>

    a promise that resolves to "success" if removing works, and rejects if something went wrong.

Static count

  • count(search: TicketCountCriteria): Promise<number>
  • Count all tickets that match the search criteria.

    Fetches a count of all tickets matching the criteria and returns the number. Note that this function is not limited by 10000 like TicketService.search.

    Calls this HTTP API: POST /v1/tickets/count?(search)

    For example:

    import * as Qminder from 'qminder-api';
    Qminder.setKey('API_KEY_HERE');
    
    const criteria = { line: 123, status: ['NEW'] };
    const count = await Qminder.tickets.count(criteria);
    console.log(count); // 14
    

    Parameters

    • search: TicketCountCriteria

      the search criteria to use

    Returns Promise<number>

    the number of tickets that match the search criteria

Static create

  • create(line: IdOrObject<Line>, ticket: Pick<Ticket, "source" | "firstName" | "lastName" | "phoneNumber" | "email" | "extra">, idempotencyKey?: string | number): Promise<Pick<Ticket, "id">>
  • Creates a new ticket and puts it into the queue as the last in the given line.

    Calls this HTTP API: POST /v1/lines/<ID>/ticket

    For example:

    import * as Qminder from 'qminder-api';
    Qminder.setKey('API_KEY_HERE');
    
    // Example 1. Create a ticket with first and last name, and phone number
    const lineId = 1234;
    const ticket: Ticket = new Qminder.Ticket({
       firstName: "Jane",
       lastName: "Smith",
       phoneNumber: 3185551234,
    });
    const ticketId = await Qminder.tickets.create(lineId, ticket);
    console.log(ticketId); // 12345678
    
    // Example 2. Create a ticket with custom fields
    const lineId = 1234;
    const ticket: Ticket = new Qminder.Ticket({
       firstName: "Sarah Jane",
       lastName: "Smith",
       extra: [ { "title": "Order ID", "value": "1234567890" } ]
    });
    const ticketId = await Qminder.tickets.create(lineId, ticket);
    console.log(ticketId); // 12345681
    
    // Example 3. Create a ticket by using a Line object to specify the line
    const ticket: Ticket = new Qminder.Ticket({
       firstName: "Sarah Jane",
       lastName: "Smith",
       extra: [ { "title": "Order ID", "value": "1234567890" } ]
    });
    const line: Line = await Qminder.lines.details(12345);
    const ticketId = await Qminder.tickets.create(line, ticket);
    console.log(ticketId); // 12345689
    
    throws

    ERROR_NO_LINE_ID when the lineId parameter is undefined or not a number.

    Parameters

    • line: IdOrObject<Line>

      the ticket's desired line

    • ticket: Pick<Ticket, "source" | "firstName" | "lastName" | "phoneNumber" | "email" | "extra">

      the ticket data

    • Optional idempotencyKey: string | number

      optional: a unique identifier that lets you safely retry creating the same ticket twice

    Returns Promise<Pick<Ticket, "id">>

    a promise that resolves to the ID of the new ticket.

Static details

  • Fetches the details of a given ticket ID and returns a Ticket object filled with data.

    Calls the following HTTP API: GET /v1/tickets/<ID>

    For example:

    import * as Qminder from 'qminder-api';
    Qminder.setKey('API_KEY_HERE');
    
    const ticket = await Qminder.tickets.details(12345);
    console.log(ticket.id); // 12345
    console.log(ticket.firstName); // Jane
    console.log(ticket.lastName); // Eyre
    
    throws

    ERROR_NO_TICKET_ID when the ticket ID is undefined or not a number.

    Parameters

    • ticket: IdOrObject<Ticket>

      the Ticket to query, by ticket ID or Ticket object

    Returns Promise<Ticket>

    the ticket's details as a Ticket object

Static edit

  • edit(ticket: IdOrObject<Ticket>, changes: TicketEditingParameters): Promise<"success">
  • Edits the ticket.

    To edit a ticket, pass the ticket ID to edit, and an object that only includes the keys that need to be changed.

    import * as Qminder from 'qminder-api';
    Qminder.setKey('API_KEY_HERE');
    // Edit a ticket's first name
    const ticket = { id: 12345, firstName: "John", lastName: "Smith" };
    const changes = { firstName: "Jane" };
    const successMessage = await Qminder.tickets.edit(ticket, changes);
    console.log(successMessage === "success"); // true if it worked
    
    throws

    ERROR_NO_TICKET_ID when the ticket ID was undefined or not a number

    throws

    ERROR_NO_TICKET_CHANGES when the ticket changes were undefined

    Parameters

    • ticket: IdOrObject<Ticket>

      the ticket to edit, either the Ticket object or the ticket's ID

    • changes: TicketEditingParameters

      an object only including changed properties of the ticket

    Returns Promise<"success">

    a Promise that resolves to "success" when editing the ticket worked

Static forward

  • forward(ticket: IdOrObject<Ticket>, line: IdOrObject<Line>, user?: IdOrObject<User>): Promise<object>
  • Forward the ticket to another queue.

    If a visitor's served at one step of the flow, they can be queued for a second service. This allows to build multi-step workflows. Only tickets with the status 'CALLED' can be forwarded.

    After forwarding, a ticket's status will be 'NEW'. For example:

    import * as Qminder from 'qminder-api';
    Qminder.setKey('API_KEY_HERE');
    
    // Example 1. Forward a ticket using ES2017 features (async and await). This code only works
    // inside an asynchronous function.
    const tickets = await Qminder.tickets.search({ status: ['CALLED'], location: 3, limit: 1 });
    if (tickets.length > 0) {
       await Qminder.tickets.forward(tickets[0], 15124);
       console.log('Success!');
    }
    
    // Example 2. Forward a ticket using regular Javascript. This doesn't use any ES6
    // features and can be deployed to a server without any pre-processing.
    Qminder.tickets.search({ status: ['CALLED'], location: 3, limit: 1 }).then(function(tickets) {
      if (tickets.length > 0) {
         Qminder.tickets.forward(tickets[0], 15124).then(function(success) {
             console.log('Success!');
         }, function(error) { console.error(error); });
      }
    });
    
    throws

    an Error when the ticket or line are missing or invalid.

    Parameters

    • ticket: IdOrObject<Ticket>

      the ticket to forward, as ticket ID or ticket object

    • line: IdOrObject<Line>

      the visitor's next line, as line ID or line object.

    • Optional user: IdOrObject<User>

      the user who forwarded the ticket, as user ID or user object. Only necessary if forwarding on behalf of a User.

    Returns Promise<object>

    a Promise that resolves when forwarding works, and rejects when it fails.

Static getEstimatedTimeOfService

  • getEstimatedTimeOfService(ticket: IdOrObject<Ticket>): Promise<number>
  • Get the estimated time that this visitor will be called for service.

    The time will be returned as a Unix timestamp (in seconds).

    Calls the HTTP API: GET /v1/tickets/<ID>/estimated-time

    import * as Qminder from 'qminder-api';
    Qminder.setKey('API_KEY_HERE');
    // Get the ticket's estimated time of service
    const lineId = 15152;
    const visitorDetails = { firstName: "Jon", lastName: "Snow" };
    const ticket = await Qminder.tickets.create(lineId, visitorDetails);
    const eta = await Qminder.tickets.getEstimatedTimeOfService(ticket);
    console.log(eta); // 1509460809, for example.
    

    Parameters

    • ticket: IdOrObject<Ticket>

      the ticket to get the estimated time for. The ticket ID can be used instead of the Ticket object.

    Returns Promise<number>

    the estimated Unix time the visitor will be called, eg 1509460809

Static getMessages

  • getMessages(ticket: IdOrObject<Ticket>): Promise<TicketMessage[]>
  • Get the ticket's SMS messages. If the location has SMS enabled, clerks can send and receive SMS messages from visitors. It works only if the visitor's phone number has been entered into Qminder.

    For example:

    import * as Qminder from 'qminder-api';
    Qminder.setKey('API_KEY_HERE');
    
    // Get list of messages with async/await in ES2017
    const messages = await Qminder.tickets.getMessages(12345678);
    if (messages.length > 0) {
      console.log(messages[0]);
      // { "body": "Hi!", "type": "INCOMING", ... }
    }
    
    // Example 2. Get list of messages with regular Javascript
    Qminder.tickets.getMessages(12345678).then(function(messages) {
        if (messages.length > 0) {
           console.log(messages[0]);
           // { "body": "Hi!", "type": "INCOMING", ... }
        }
    });
    
    throws

    ERROR_NO_TICKET_ID if the ticket is missing from the arguments, or invalid.

    Parameters

    • ticket: IdOrObject<Ticket>

      The ticket to get the message list for. The ticket ID can be used instead of the Ticket object.

    Returns Promise<TicketMessage[]>

    a Promise that resolves to a list of ticket messages

Static markNoShow

  • markNoShow(ticket: IdOrObject<Ticket>): Promise<"success">
  • Mark a ticket as "no-show".

    If a visitor did not appear for service, they should be marked "no-show".

    Only called tickets (with the status 'CALLED') can be marked as "no-show".

    Parameters

    • ticket: IdOrObject<Ticket>

      The ticket to mark no-show. The ticket ID can be used instead of the Ticket object.

    Returns Promise<"success">

    A promise that resolves to "success" when marking no-show works, and rejects when something went wrong.

Static markServed

  • markServed(ticket: IdOrObject<Ticket>): Promise<"success">
  • Mark a ticket served.

    If a visitor has been serviced, they should be marked served immediately.

    Only called tickets (with the status 'CALLED') can be marked served.

    Parameters

    • ticket: IdOrObject<Ticket>

      The ticket to mark served. The ticket ID can be used instead of the Ticket object.

    Returns Promise<"success">

    a promise that resolves to 'success' if all went well.

Static recall

  • recall(ticket: IdOrObject<Ticket>): Promise<"success">
  • Recall a ticket.

    Recalling a ticket will notify the visitor again.

    Only called tickets (with the status 'CALLED') can be recalled.

    Parameters

    • ticket: IdOrObject<Ticket>

      The ticket to recall. The ticket ID can be used instead of the Ticket object.

    Returns Promise<"success">

    a promise that resolves to 'success' if all went well.

Static removeLabel

  • removeLabel(ticket: IdOrObject<Ticket>, label: string, user: IdOrObject<User>): Promise<"success">
  • Remove a label from the ticket.

    This API call removes the label from a ticket's label list, by the label's text.

    For example:

    import * as Qminder from 'qminder-api';
    Qminder.setKey('API_KEY_HERE');
    
    const myUserId = 51000;
    const ticket = 1234567;
    const label = "Hello";
    await Qminder.tickets.removeLabel(ticket, label, myUserId);
    console.log('It worked!');
    

    Parameters

    • ticket: IdOrObject<Ticket>

      The ticket to remove a label from. The ticket ID can be used instead of the Ticket object.

    • label: string

      The label to remove, for example, "Has Cool Hair"

    • user: IdOrObject<User>

      The user who is removing the label, for example 9500

    Returns Promise<"success">

    A promise that resolves to "success" when removing the label worked, and rejects when something went wrong.

Static reorder

  • reorder(ticket: IdOrObject<Ticket>, afterTicket: IdOrObject<Ticket>): Promise<"success">
  • Reorder a ticket after another ticket.

    Calls this HTTP API: POST /v1/tickets/<ID>/reorder

    For example:

    import * as Qminder from 'qminder-api';
    Qminder.setKey('API_KEY_HERE');
    
    const ticket1 = { id: 12345 };
    const ticket2 = { id: 12346 };
    const ticket3 = { id: 12347 };
    // Queue: ticket1, ticket2, ticket3
    // Ticket 3 will be put after Ticket 1
    Qminder.tickets.reorder(ticket3, ticket1);
    // Queue: ticket1, ticket3, ticket2
    

    Parameters

    • ticket: IdOrObject<Ticket>

      The ticket to reorder. The ticket ID can be used instead of the Ticket object.

    • afterTicket: IdOrObject<Ticket>

      the ticket to reorder after, or null if reordering to be first in the queue.

    Returns Promise<"success">

    resolves to 'success' when it worked

Static returnToQueue

  • returnToQueue(ticket: IdOrObject<Ticket>, user: IdOrObject<User>, position: DesiredQueuePosition): Promise<"success">
  • Return a ticket to the queue.

    Returning a ticket to the queue makes the ticket's status go back to 'NEW', Ticket Changed and Reordered events will fire, and the ticket will appear back in the queue. The ticket can be ordered to be first in queue or the last in queue, depending on the reason the visitor needs to go back to the queue and when they will be back for service.

    Only called tickets (with the status 'CALLED') can be returned to the queue.

    Parameters

    • ticket: IdOrObject<Ticket>

      The ticket to return to queue. The ticket ID can be used instead of the Ticket object.

    • user: IdOrObject<User>

      The user that returned the ticket to the queue. The user ID can be used instead of the User object.

    • position: DesiredQueuePosition

      The position where to place the returned ticket. Either 'FIRST' or 'LAST'.

    Returns Promise<"success">

    a promise that resolves to "success" if it worked, and rejects if something went wrong.

Static search

  • search(search: TicketSearchCriteria): Promise<Ticket[]>
  • Searches for tickets according to the given search criteria. Resolves to a list of tickets that match the search.

    Only the first 10000 tickets are returned.

    The various search criteria to use are documented under {@link TicketSearchCriteria}.

    This method calls the following HTTP API: GET /v1/tickets/search?<CRITERIA>

    For example:

    import * as Qminder from 'qminder-api';
    Qminder.setKey('API_KEY_HERE');
    // Example 1. Search line 1234 for tickets created after July 9, 2018, ordered by IDs,
    // smallest first.
    const criteria = {
        line: [ 1234 ],
        order: 'id ASC',
        minCalled: "2018-07-09T00:00:00Z"
    };
    const tickets: Array<Ticket> = Qminder.tickets.search(criteria);
    const ticket: Ticket = tickets[0];
    console.log(ticket.id); // 12345
    console.log(ticket.firstName); // John
    console.log(ticket.lastName);  // Smith
    
    // Example 2. Search tickets, including their SMS conversation in the response data.
    const criteria = {
        ...,
        responseScope: 'MESSAGES'
    };
    const tickets: Array<Ticket> = Qminder.tickets.search(criteria);
    const ticket: Ticket = tickets[0];
    // NOTE: only included in the response data, if criteria.responseScope === 'MESSAGES'
    // This data can also be loaded with Qminder.tickets.getMessages(Ticket)
    const messages: Array<TicketMessage> = ticket.messages;
    console.log(messages[0].body); // "It's your turn!"
    

    Parameters

    • search: TicketSearchCriteria

      the search criteria

    Returns Promise<Ticket[]>

    A promise that resolves to matching tickets.

Static sendMessage

  • sendMessage(ticket: IdOrObject<Ticket>, message: string, user: IdOrObject<User>): Promise<"success">
  • Send a new SMS message to a visitor.

    For example:

    import * as Qminder from 'qminder-api';
    Qminder.setKey('API_KEY_HERE');
    
    // Example 1. Send the message with async/await in ES2017
    const success = await Qminder.tickets.sendMessage(12345678,
                           "Hello! Go get some coffee now!",
                           { id: 14142 });
    console.log('It worked!');
    // NOTE: If sending a message fails, then the async function will be rejected.
    
    // Example 2. Send the message with regular Javascript
    Qminder.tickets.sendMessage(
           12345678,
           "Hello! Free coffee time!",
           { id: 14245 }
    ).then(function(success) {
        console.log("It works!");
    }, function(error) {
        console.log("Something went wrong while sending the message.");
    });
    

    Parameters

    • ticket: IdOrObject<Ticket>

      The ticket to send a message to. The user ID may also be used.

    • message: string

      the message to send, as a text string, for example "Welcome to our location!"

    • user: IdOrObject<User>

      the user who is sending the message. The user ID may also be used.

    Returns Promise<"success">

    a promise that resolves to the string "success" if it works, and rejects when something goes wrong.

Static setExternalData

  • setExternalData(ticket: IdOrObject<Ticket>, provider: string, title: string, data: any): Promise<"success">
  • Add external data to a ticket.

    Parameters

    • ticket: IdOrObject<Ticket>

      The ticket to add external data to. The ticket ID can be used instead of the Ticket object.

    • provider: string

      Provider of the data. One record per provider is allowed.

    • title: string

      Title for the data

    • data: any

      The data to set

    Returns Promise<"success">

    promise that resolves to 'success' if all was OK and rejects if something else went wrong.

Static unassign

  • unassign(ticket: IdOrObject<Ticket>, unassigner: IdOrObject<User>): Promise<"success">
  • Un-assign a ticket. This returns the ticket to the unassigned list. This call works only for Tickets that have the status: 'NEW'.

    For example:

    import * as Qminder from 'qminder-api';
    Qminder.setKey('API_KEY_HERE');
    
    // Example 1. Using unassign with async/await in latest Javascript/ES6 standard
    const ticketID = 141412345;
    const myUserID = 123;
    try {
      await Qminder.tickets.unassign(ticketID, myUserID);
      console.log('Ticket unassign worked!');
    } catch (error) {
      console.log('Ticket unassign failed', error);
    }
    
    // Example 2. Using unassign without async/await, with plain promises.
    const ticketID = 1452521;
    const myUserID = 529;
    Qminder.tickets.unassign(ticketID, myUserID).then(function(success) {
      console.log('Ticket unassign worked!');
    }, function(error) {
      console.log('Ticket unassign failed!', error);
    });
    
    // Example 3. Using unassign with a Ticket object and async/await in latest Javascript/ES6
    // standard
    const myUserID = 42049;
    const tickets = await Qminder.tickets.search({ line: 12345 });
    const ticket = tickets[0];
    await Qminder.tickets.unassign(ticket, myUserID);
    

    Parameters

    • ticket: IdOrObject<Ticket>

      the ticket object or the ticket's ID that needs un-assignment

    • unassigner: IdOrObject<User>

      the User who un-assigned the ticket, for example current user's ID

    Returns Promise<"success">

    a Promise that resolves when unassigning works and rejects when unassigning fails

Generated using TypeDoc