The `Ticket` Class
Learn how to create, update and list the tickets for an event using the Eventbrite API.
We'll cover the following
Tickets are associated with the events, and we create an object of the ticket
class for an event. We have to add at least one ticket
class to an event before publishing it; without it, Eventbrite won’t allow us to publish the event on the platform. Eventbrite provides three fundamental ticket types: free, paid, and donation.
Ticket creation
Let’s create a ticket for an event. The following URL utilizes the POST
request method to create a ticket
class:
https://www.eventbriteapi.com/v3/events/{event_id}/ticket_classes/
Some important request parameters of ticket_class
are as follows:
Request parameters
Object | Type | Category | Description |
| String | Required | Name of the |
| String | Optional | Description of the ticket |
| Boolean | Required | Specifies if the event is paid or free |
| String | Optional (required if the ticket is paid) | Cost of the ticket. The cost is required if the event is paid; otherwise, it's optional. The |
| Boolean | Optional | Specifies if the ticket includes a donation or not |
| Number | Required | Audience capacity of the event |
| Number | Optional | Minimum tickets that can be purchased per order |
| Number | Optional | Maximum tickets that can be purchased per order |
| Array | Optional | List of channels for sales; supported channels are |
| String | Optional | List of delivery methods; supported methods are |
| String | Optional | Inventory tier ID associated with the `ticket` class |
| String | Optional | Whether or not to include a PDF of the ticket |
Let’s create a free ticket for an event with a capacity
of .
const endpointUrl = new URL('https://www.eventbriteapi.com/v3/events/{{EVENT_ID}}/ticket_classes/');const headerParameters = {'Authorization': 'Bearer {{PRIVATE_TOKEN}}','Content-Type': 'application/json'};const bodyParameters = JSON.stringify({"ticket_class": {"name": "Ticket Name","free": "True","capacity": "100","minimum_quantity": "1","maximum_quantity": "10","sales_channels": ["online", "atd"],"delivery_methods": ["electronic"]}});const options = {method: 'POST',headers: headerParameters,body: bodyParameters,};async function createTicket() {try {const response = await fetch(endpointUrl, options);printResponse(response);} catch (error) {printError(error);}}// Calling function to make API callcreateTicket();
- Line 1: We define the endpoint URL, and it has
EVENT_ID
has the URL parameter. - Line 3–6: We define the header, which includes the authorization token and content type.
- Line 8–18: We define the request parameters required to create a ticket for an event.
- Line 20–24: We set the API call options by specifying the header and body, and by setting the request method as
POST
. - Line 26–33: We create a function
createTicket
to make an API call using fetch and to handle any exception if it occurs. The custom functionsprintResponse
andprintError
print the respective objects. - Line 36: We invoke the
createTicket
function.
The code in the below widget is an example of creating a paid ticket costing dollars.
{"ticket_class": {"name": "Ticket Name","free": "False","cost": "USD,2000","capacity": "100","minimum_quantity": "1","maximum_quantity": "10","sales_channels": ["online", "atd"],"delivery_methods": ["electronic"]}}
The response is an object of the ticket class with its own id
. Now this ticket_class
is associated with the event provided.
Note: One
ticket
class object represents one ticket associated with an event, and there can be more than one ticket for an event.
List tickets
We can list all the associated ticket
classes with an event. The following URL utilizes the GET
request method to retrieve the ticket
classes of an event:
https://www.eventbriteapi.com/v3/events/{event_id}/ticket_classes/
We have to provide the {event_id}
in the URL, and it will return a paginated response with an array of all ticket
classes associated with the {event_id}
.
const endpointUrl = new URL('https://www.eventbriteapi.com/v3/events/{{EVENT_ID}}/ticket_classes/');const headerParameters = {'Authorization': 'Bearer {{PRIVATE_TOKEN}}','Content-Type': 'application/json'};const options = {method: 'GET',headers: headerParameters,};async function retrieveTickets() {try {const response = await fetch(endpointUrl, options);printResponse(response);} catch (error) {printError(error);}}// Calling function to make API callretrieveTickets();
Update ticket
We can update the ticket
class by using the ticket
class id
. The following URL utilizes the POST
request method to update a ticket
class:
https://www.eventbriteapi.com/v3/events/{event_id}/ticket_classes/{ticket_class_id}/
It requires the {event_id}
and the {ticket_class_id}
associated with the event in the URL. We can update any attribute with a valid value. Let’s update the ticket name
and capacity
of the event.
const endpointUrl = new URL('https://www.eventbriteapi.com/v3/events/{{EVENT_ID}}/ticket_classes/{{TICKET_CLASS_ID}}/');const headerParameters = {'Authorization': 'Bearer {{PRIVATE_TOKEN}}','Content-Type': 'application/json'};const bodyParameters = JSON.stringify({"ticket_class": {"name": "New Ticket Name","capacity": "200"}});const options = {method: 'POST',headers: headerParameters,body: bodyParameters,};async function updateTicket() {try {const response = await fetch(endpointUrl, options);printResponse(response);} catch (error) {printError(error);}}// Calling function to make API callupdateTicket();
This operation will return the updated object of the ticket
class associated with the given EVENT_ID
.