Create events with the Eventbrite API
Published: 2019-12-11 17:37:57

_**Update: August 2020. The second half of this article is still useful, but Bearer no longer handles integrations. Instead, check out [Pizzly](https://github.com/Bearer/Pizzly), our open source project for integrating with APIs, and take a look at [Corentin's guide on setting it up](https://dev.to/bearer/how-to-integrate-with-the-google-sheets-api-in-2-minutes-569o).**_

Eventbrite's powerful event discovery and management platform is completely accessible through their developer platform. Version 3 is a REST API that uses OAuth2 for authorization, which means it's not only familiar, but there's a [Bearer integration for it](https://www.bearer.sh/integrations/40/eventbrite-api).

In this article we will:

1. Set up your application on Eventbrite and get the credentials.
2. Connect Bearer and the [@bearer/node client](https://github.com/Bearer/bearer-js/tree/master/packages/node) to handle the auth and requests.
3. Create, review, and publish a new event.

## Setting up an app on the Eventbrite platform

Eventbrite requires an account on their platform as well as an API key to get started. Here's a brief overview, or check out our step-by-step guide on [How to configure the Eventbrite API](https://www.bearer.sh/integrations/40/eventbrite-api/articles/how-to-setup-the-eventbrite-api).

First, get your key from the [Eventbrite Platform page](https://www.eventbrite.com/platform).

![eventbrite-platform](https://blog.bearer.sh/content/images/2019/12/eventbrite-platform.png)

You can then configure your application and get any necessary credentials on the [account page](https://www.eventbrite.com/account-settings/apps).

![eventbrite-api-keys](https://blog.bearer.sh/content/images/2019/12/eventbrite-api-keys.png)

There, you'll find the client ID (API Key) and client secret needed for the next step. This is also the place to set your application name, redirect URI, and application URI.

> ⚠️ Make sure `https://int.bearer.sh/v2/auth/callback` is set as the OAuth redirect URI on your Eventbrite app settings under "Key Info"

## Set up the Eventbrite integration and connect Bearer

If you haven't already, activate the [Eventbrite Integration](https://app.bearer.sh/apis?newModal=true&api=40) on [Bearer](https://bearer.sh). For more on setting up an integration, see [the getting started guide](https://docs.bearer.sh/getting-started).

Once the integration is enabled, you can access it in your app using one of Bearer's clients. For this tutorial, we'll use the [@bearer/node](https://github.com/Bearer/bearer-js/tree/master/packages/node) client.

We will only create events from a single user, you, which means you will use your own Auth ID. In case you want to create events for third-party users, make sure to [generate an identity for them](https://docs.bearer.sh/faq/connect-button) to retrieve their Auth ID.

Get started by initializing a new node application:

```bash
npm init --yes
```

Install the Bearer client for Node.js

```bash
npm install @bearer/node
```

With the integration enabled in your app, you can now use it to make API calls to Eventbrite.

Create a new file `index.js`, require the Bearer client, and initialize the integration:

```javascript
// npm install @bearer/node
const bearer = require("@bearer/node")

// Initialize the client
const client = bearer("YOUR-SECRET-KEY")

// Set up the Eventbrite Integration
const eventBrite = client.integration("eventbrite").auth('YOUR-AUTH-ID)
```

Make sure to replace `YOUR-SECRET-KEY` and `YOUR-AUTH-ID` with the correct values.

If you've set up Bearer before, this will be familiar. The secret key comes from your [Bearer settings page](https://app.bearer.sh/settings), and the auth ID comes from the identity generated when you set up Eventbrite within Bearer.

We can test the integration and make sure everything is working by having the client make a call to the API:

```javascript
eventBrite.get("users/me/organizations").then(({ data }) => {
  console.log(data)
})
```

When you run `node index.js`, you should see a list of all organizations that the authenticated user belongs to. This is important for the next step, creating a new event.

## Create, review, and publish a new event

With the client set up, now you can create a new event in the organization of your choice. The Eventbrite API provides an [endpoint for creating new events](https://www.eventbrite.com/platform/api#/reference/event/retrieve/create-an-event). The key requirement, aside from the event details, is the organization ID (like one obtained from the previous example).

```javascript
eventBrite
  .post("organizations/ORG-ID/events/", {
    body: {
      event: {
        name: {
          html: "Test Event"
        },
        start: {
          timezone: "America/Los_Angeles",
          utc: "2019-12-01T02:00:00Z"
        },
        end: {
          timezone: "America/Los_Angeles",
          utc: "2019-12-01T05:00:00Z"
        },
        currency: "USD"
      }
    }
  })
  .then(({ data }) => {
    console.log(data)
  })
```

In the code above, we've sent only the required properties needed for a new event. Specifically: the `name`, `start` time, `end` time, and `currency`. Check [the documentation](https://www.eventbrite.com/platform/api#/reference/event/retrieve/create-an-eventhttps://www.eventbrite.com/platform/api#/reference/event/retrieve/create-an-event) for a full list of possible properties you can change.

The response we get back contains details on the new event, including it's `id`, `url` and `status`. **The current status will be "draft".**

All events are created as drafts, and must be published with a separate API call to the [publish endpoint](https://www.eventbrite.com/platform/api#/reference/event/publish/publish-an-event).

If you try to publish the event you just created, you'll receive an error. Events need tickets before they can be published. To do this, you'll use the [create ticket class endpoint](https://www.eventbrite.com/platform/api#/reference/ticket-class/create).

```javascript
eventBrite
  .post("/events/EVENT-ID/ticket_classes/", {
    body: {
      ticket_class: {
        name: "General Entry",
        free: true,
        quantity_total: 50
      }
    }
  })
  .then(({ data }) => console.log(data))
  .catch(console.error)
```

Ticket classes require at least the `name`, `free`, `quantity_total`, and for paid tickets the `cost` properties.

With the event created, and the ticket class added, it is now possible to publish the event.

```javascript
eventBrite
  .post("events/EVENT-ID/publish/")
  .then(({ data }) => console.log(data))
  .catch(console.error)
```

If any required data is missing, the error response will let you know. Otherwise, a successful publish will return `{ published: true }`.

## Takeaways and things to try

Creating events from scratch with the Eventbrite API is a multi-step task. If you find yourself creating many of the same type of event, an easier option is to [copy an existing event](https://www.eventbrite.com/platform/api#/reference/event/copy/copy-an-event) and use it as a base. A few other useful things you can do:

- Create private events by setting the `listed` property to false.
- [Retrieve Attendee data](https://www.eventbrite.com/platform/api#/reference/attendee/) to connect your users with an events attendees.
- Use the [media endpoint](https://www.eventbrite.com/platform/api#/reference/media) to upload images to an event.

_Like this tutorial or have an idea for one you'd like to see? Connect with us [@BearerSH](https://twitter.com/BearerSH)_