> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

> **Deprecated.** This resource is deprecated.

# Method name: tickets()

# Method package: wixEventsFrontend

# Method menu location: wixEventsFrontend --> tickets

# Method Link: https://dev.wix.com/docs/velo/apis/wix-events-frontend/tickets.md

# Method Description:

Retrieves an object containing ticketing functionality.

> **Migration Instructions**
>
> To stay compatible with future changes, migrate to relevant replacement methods in [Tickets](https://dev.wix.com/docs/velo/apis/wix-events-frontend/tickets/introduction.md).
>
> To migrate to the new replacement methods:
>
> 1. Add a backend file to your site.
>
> 2. Write a code so that it replaces the relevant methods. Export your backend function so that it can be used in the frontend.
>
> 3. Import your backend function into the frontend file. Test your changes to make sure your code behaves as expected.

Use the `Tickets` object to reserve and checkout tickets for an event.
 > **Note:** The frontend Events APIs aren't functional when previewing a site. View a published version of a site to see their complete functionality.



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Reserve, checkout, and update tickets

```javascript
import wixEventsFrontend from 'wix-events-frontend';
import wixData from 'wix-data';
import wixPayFrontend from 'wix-pay-frontend';

let eventId;
let reservationId;
let orderNumber;
let tickets;

$w.onReady(function () {
  // Retrieve data and set up page
  await getData();
  $w("#ticketRepeater").onItemReady(displayTickets);
  $w("#ticketRepeater").data = tickets;

  // Define button click actions
  $w("#reservationButton").onClick(reserveTickets);
  $w("#checkoutButton").onClick(checkoutTickets);
  $w("#updateButton").onClick(updateTickets);

  // Verify coupon code when it is entered
  $w("#couponCode").onCustomValidation(verifyCouponCode);
});

async function getData() {
  // Run a query that returns only one event. Add
  // additional filtering to the query if necessary.
  const eventResults = await wixData.query("Events/Events")
    .eq("title", "My Event")
    .find();

  if (eventResults.items.length > 0) {
    eventId = eventResults.items[0]._id;

    // Get tickets for the event
    const ticketResults = await wixData.query("Events/Tickets")
      .eq("event", eventId)
      .find();

      if (ticketResults.items.length > 0) {
        tickets = ticketResults.items;
      } else {
        $w("#ticketRepeater").hide();
        console.log("Could not find tickets");
      }
  } else {
    console.log("Could not find event");
  }
}

function displayTickets($item, itemData, index) {
  $item("#ticketName").text = itemData.name;
  $item("#ticketPrice").text = itemData.price.toString();
  $item("#ticketQuantity").value = 0;
}

function reserveTickets() {
  const selectedTickets = getSelectedTickets();

  wixEventsFrontend.tickets.reserve(eventId, selectedTickets)
    .then((reservation) => {
      reservationId = reservation.id;
    })
    .catch((error) => {
      console.log("Error", error.message)
    });
}

function getSelectedTickets() {
  let selectedTickets = [];

  $w("#ticketRepeater").forEachItem(($item, itemData, index) => {
    if ($item("#ticketQuantity").value > 0) {
      selectedTickets.push( {
        "ticketId": itemData._id,
        "quantity": $item("#ticketQuantity").value
      });
    }
  });

  return selectedTickets;
}

function checkoutTickets() {
  wixEventsFrontend.tickets.checkout(eventId, reservationId, {
    "formValues": getFormValues(),
    "coupon": $w("#couponCode").value
  })
    .then(({order}) => {
      orderNumber = order.orderNumber
      wixPayFrontend.startPayment(order.paymentId);
      // Note that PDF tickets are available before payment is complete
      $w("#ticketsPdfLink").value = order.ticketsPdf;
    })
    .catch((error) => {
      console.log("Error", error.message)
    });
}

function updateTickets() {
  wixEventsFrontend.tickets.updateOrder(eventId, orderNumber, {
    "formValues": getFormValues()
  })
    .catch((error) => {
      console.log("Error", error.message)
    });
}

function verifyCouponCode(value, reject) {
  const coupon = $w("#couponCode").value;
  wixEventsFrontend.tickets.verifyCoupon(eventId, reservationId, coupon) 
    .then((result) => {
      if (result.discountErrors) {
        // handle verification failure
        $w("#couponCode").updateValidityIndication();
        $w("#couponErrorMsg").show();
        $w("#couponSuccessMsg").hide();
        reject("Coupon is invalid");
      } else {
        // handle coupon verified
        $w("#couponErrorMsg").hide()
        $w("#couponSuccessMsg").show()
      }
    });
}

function getFormValues() {
  return [
    {"name": "firstName", "value": $w("#firstName").value},
    {"name": "lastName", "value": $w("#lastName").value},
    {"name": "email", "value": $w("#email").value},
    {"name": "custom", "value": $w("#foodAllergies").value},

    // When a form contains an address, the way you format the
    // address information for submission depends on what type
    // of input elements you use to gather that information.

    // Wix address input element.
    {"name": "address", "value": $w("#address").value},

    // Single element which is not an address
    // input element, such as a text input.
    {"name": "address", "value": [$w("#address").value]},

    // Multiple elements for the
    // various parts of an address.
    {
      "name": "address", 
      "value": [
        $w("#street").value,
        $w("#city").value,
        $w("#state").value,
        $w("#country").value,
        $w("#postalCode").value
      ]
    },

    // When a form contains an input for adding more guests to an
    // RSVP, format the guest names for submission in an array
    // where each element is the full name of a guest.
    {"name": "additionalGuests", "value": $w("#additionalGuests").value},
    {
      "name": "guestNames",
      "value": [
        `${$w("#guest1FirstName").value} ${$w("#guest1LastName").value}`,
        `${$w("#guest2FirstName").value} ${$w("#guest2LastName").value}`,
      ]
    }
  ];
}
```

---