Publish and Unpublish Event
Learn how to publish and unpublish an event using the Eventbrite API.
We'll cover the following
Publish an event
We need to publish the events to make them viewable to the targeted audience. The event should have all the necessary data, including the event name, description, organizer, ticket class, and a valid payment method.
The following URL utilizes the POST
request method to publish an event:
https://www.eventbriteapi.com/v3/events/{event_id}/publish/
We need to provide the {event_id}
in the URL to publish it. If all goes well, it returns a JSON object that has one attribute published
with the value true
. Otherwise, it returns a JSON object with the error_description
and status_code
attributes.
Let’s take a look at an example that publishes the previously created event, which should be associated with at least one ticket class.
const endpointUrl = new URL('https://www.eventbriteapi.com/v3/events/{{EVENT_ID}}/publish/');const headerParameters = {'Authorization': 'Bearer {{PRIVATE_TOKEN}}','Content-Type': 'application/json'};const options = {method: 'POST',headers: headerParameters};async function publishEvent() {try {const response = await fetch(endpointUrl, options);printResponse(response);} catch (error) {printError(error);}}// Calling function to make API callpublishEvent();
- Line 1: We define the endpoint URL to publish an event, and it has
EVENT_ID
as the URL parameter. - Line 3–6: We define the header, which includes the authorization token and content type.
- Line 8–11: We set the API call options by specifying the header and by setting the request method as
POST
. - Line 13–20: We create a function
publishEvent
to make an API call using fetch and to handle any exception if it occurs. The custom functionsprintResponse
andprintError
print the respective objects. - Line 23: We invoke the
publishEvent
function.
Unpublish an event
Eventbrite also provides the ability to unpublish an event at any time. An event can only be unpublished if it doesn’t have any pending or completed ticket orders.
The following URL utilizes the POST
request method to unpublish an event:
https://www.eventbriteapi.com/v3/events/{event_id}/unpublish/
We need to provide the {event_id}
in the URL to unpublish the event. If all goes well, it returns a JSON object with one attribute unpublished
that has the value true
. Otherwise, it returns a JSON object with the error_description
and status_code
attributes.
Let’s take a look at an example of unpublishing a published event.
const endpointUrl = new URL('https://www.eventbriteapi.com/v3/events/{{EVENT_ID}}/unpublish/');const headerParameters = {'Authorization': 'Bearer {{PRIVATE_TOKEN}}','Content-Type': 'application/json'};const options = {method: 'POST',headers: headerParameters};async function unpublishEvent() {try {const response = await fetch(endpointUrl, options);printResponse(response);} catch (error) {printError(error);}}// Calling function to make API callunpublishEvent();
In the code above, in line 1, we define the endpoint URL to unpublish an event, using the EVENT_ID
as the URL parameter.