David Stockdale's Scrapcode

EventBrite via Google Sheets

A while ago I was tasked with creating a Google Sheet which could retrieve a list of event attendees using the EventBrite API.

I found it to be rather easy to retrieve various information and figured I’ve make a post reminding me how to do it later.

Over a year later and I finally got around to writing up that post.

Get Event Attendees

To simply get the attendees of your event you will need both an Access Token and the Event ID.

The Access Token can be obtained through the API Keys page of your Eventbrite account.

The Event ID you can see in the URL of the event like in the example below:

Once you have these two pieces of info you can use a simple bit of Apps Script such as this:

function getEventAttendees(eId) {
  var accessToken = '[Your Access Token]'; // Replace with your actual access token
  var eventId = eId; // Replace with your specific event ID
  var url = 'https://www.eventbriteapi.com/v3/events/' + eventId + '/attendees/';
  
  var options = {
    'method': 'get',
    'headers': {
      'Authorization': 'Bearer ' + accessToken,
      'Content-Type': 'application/json'
    }
  };
  
  try {
    var response = UrlFetchApp.fetch(url, options);
    var json = JSON.parse(response.getContentText());
    var attendees = json.attendees;
    
    attendees.forEach(function(attendee) {
      Logger.log('Name: ' + attendee.profile.name + ', Email: ' + attendee.profile.email);
    });
  } catch (e) {
    Logger.log('Error fetching attendees: ' + e.toString());
  }
}

Which you can then test with a simple test function such as this:

function testEventAttendees() {
  getEventAttendees('[Your Event ID]');
}

or make it into a usable sheet function

Simply by making a function name nothing but capitals you can turn it into a usable sheet function.

function GETEVENTATTENDEENAMES(eId) {
  var accessToken = '[Your Access Token]'; // Replace with your actual access token
  var eventId = eId; // Replace with your specific event ID
  var url = 'https://www.eventbriteapi.com/v3/events/' + eventId + '/attendees/';
  
  var options = {
    'method': 'get',
    'headers': {
      'Authorization': 'Bearer ' + accessToken,
      'Content-Type': 'application/json'
    }
  };
  
  try {
    var response = UrlFetchApp.fetch(url, options);
    var json = JSON.parse(response.getContentText());
    var attendees = json.attendees;

    attendees.forEach(function(attendee) {
      Logger.log('Name: ' + attendee.profile.name + ', Email: ' + attendee.profile.email);
    });

    var names = attendees.map(function(attendee) {
      return [attendee.profile.name]; // Return names as arrays to form rows
    });

    return names;

    // return attendees.profile.name;
  } catch (e) {
    Logger.log('Error fetching attendees: ' + e.toString());
  }
}

Which makes it as usable as any other sheet function.

get attendee emails

It is similarly easy to access a list of attendee emails with this simple script:

function GETEVENTATTENDEEMAILS(eId) {
  var accessToken = '[Your Access Token]'; // Replace with your actual access token
  var eventId = eId; // Replace with your specific event ID
  var url = 'https://www.eventbriteapi.com/v3/events/' + eventId + '/attendees/';
  
  var options = {
    'method': 'get',
    'headers': {
      'Authorization': 'Bearer ' + accessToken,
      'Content-Type': 'application/json'
    }
  };
  
  try {
    var response = UrlFetchApp.fetch(url, options);
    var json = JSON.parse(response.getContentText());
    var attendees = json.attendees;

    attendees.forEach(function(attendee) {
      Logger.log('Name: ' + attendee.profile.name + ', Email: ' + attendee.profile.email);
    });

    var emails = attendees.map(function(attendee) {
      return [attendee.profile.email]; // Return emails as arrays to form rows
    });

    return emails;

    // return attendees.profile.name;
  } catch (e) {
    Logger.log('Error fetching attendees: ' + e.toString());
  }
}

Get checked in attendees

Next I was asked to get a list of the attendees who actually checked in:

function GETCHECKEDINATTENDEES(eId) {
  var accessToken = '[Your Access Token]'; // Replace with your actual access token
  var eventId = eId; // Replace with your specific event ID
  var url = 'https://www.eventbriteapi.com/v3/events/' + eventId + '/attendees/';

  var options = {
    'method': 'get',
    'headers': {
      'Authorization': 'Bearer ' + accessToken,
      'Content-Type': 'application/json'
    }
  };

  try {
    var response = UrlFetchApp.fetch(url, options);
    var json = JSON.parse(response.getContentText());
    var attendees = json.attendees;

    if (!attendees || attendees.length === 0) {
      return 'No attendees available';
    }

    // Filter checked-in attendees and extract their names
    var checkedInAttendees = attendees
      .filter(function(attendee) {
        return attendee.checked_in; // Only include attendees who have checked in
      })
      .map(function(attendee) {
        return [attendee.profile.name]; // Return names as arrays to form rows
      });

    // Check if there are any checked-in attendees
    if (checkedInAttendees.length === 0) {
      return ;
    }

    return checkedInAttendees; // Return as a 2D array for column output

  } catch (e) {
    Logger.log('Error fetching checked in attendees: ' + e.toString());
  }
}

Much like the list of attendees this formula can return the same attendee multiple times if they have multiple tickets.

But you can easily clean up this list with some use of UNIQUE and COUNTIF.

get event title

And of course using the API to get something as simple as the event’s title is easily done with some script:

function GETEVENTTITLE(eventId) {
  var accessToken = '[Your Access Token]'; // Replace with your actual access token
  // URL for Eventbrite API to fetch event details
  var url = 'https://www.eventbriteapi.com/v3/events/' + eventId + '/';

  var options = {
    'method': 'get',
    'headers': {
      'Authorization': 'Bearer ' + accessToken,
      'Content-Type': 'application/json'
    }
  };

  try {
    var response = UrlFetchApp.fetch(url, options);
    var json = JSON.parse(response.getContentText());
    return json.name.text; // Return the event title
  } catch (e) {
    Logger.log('Error fetching name: ' + e.toString());
  }
}

get event date and time

Next here is a script for getting the date and time of the event:

function GETEVENTDATETIME(eventId) {
  var accessToken = '[Your Access Token]'; // Replace with your actual access token
  // URL for Eventbrite API to fetch event details
  var url = 'https://www.eventbriteapi.com/v3/events/' + eventId + '/';

  var options = {
    'method': 'get',
    'headers': {
      'Authorization': 'Bearer ' + accessToken,
      'Content-Type': 'application/json'
    }
  };

  try {
    var response = UrlFetchApp.fetch(url, options);
    var json = JSON.parse(response.getContentText());
    
    // Get the event's start date and time
    var dateTime = new Date(json.start.local);
    return dateTime; // Return the date and time as a single string
  } catch (e) {
    Logger.log('Error fetching Date: ' + e.toString());
  }
}

Which should be formatted to look something like this:

get event location

The event location can be retrieved with this bit of script:


function GETEVENTLOCATION(eventId) {
  var accessToken = '[Your Access Token]'; // Replace with your actual access token
  // URL for Eventbrite API to fetch event details
  var url = 'https://www.eventbriteapi.com/v3/events/' + eventId + '/';

  var options = {
    'method': 'get',
    'headers': {
      'Authorization': 'Bearer ' + accessToken,
      'Content-Type': 'application/json'
    }
  };

  try {
    var response = UrlFetchApp.fetch(url, options);
    var json = JSON.parse(response.getContentText());

    // Extract venue information
    var venueId = json.venue_id; // Fetch the venue ID
    if (!venueId) {
      return 'Venue information not available';
    }

    // Fetch the venue details
    var venueUrl = 'https://www.eventbriteapi.com/v3/venues/' + venueId + '/';
    var venueResponse = UrlFetchApp.fetch(venueUrl, options);
    var venueJson = JSON.parse(venueResponse.getContentText());

    // Combine location details
    var address = venueJson.address.localized_address_display;
    return address || 'Location details not available';
  } catch (e) {
    Logger.log('Error fetching Location: ' + e.toString());
  }
}

get event ticket prices

And finally the event ticket prices can be retrieved with this script:

function GETEVENTTICKETPRICES(eventId) {
  var accessToken = '[Your Access Token]'; // Replace with your actual access token
  // URL for Eventbrite API to fetch ticket classes
  var url = 'https://www.eventbriteapi.com/v3/events/' + eventId + '/ticket_classes/';

  var options = {
    'method': 'get',
    'headers': {
      'Authorization': 'Bearer ' + accessToken,
      'Content-Type': 'application/json'
    }
  };

  try {
    var response = UrlFetchApp.fetch(url, options);
    var json = JSON.parse(response.getContentText());
    var ticketClasses = json.ticket_classes;

    if (!ticketClasses || ticketClasses.length === 0) {
      return 'No ticket classes available';
    }

    // Prepare an array to hold ticket information
    var ticketInfo = [['Ticket Name', 'Base Price', 'Currency']];

    // Iterate through each ticket class to extract pricing details
    ticketClasses.forEach(function(ticketClass) {
      var name = ticketClass.name;
      var basePrice = ticketClass.cost ? ticketClass.cost.value / 100 : 0; // Convert from cents to dollars
      var currency = ticketClass.cost ? ticketClass.cost.currency : 'N/A';
      ticketInfo.push([name, basePrice, currency]);
    });

    return ticketInfo; // Return as a 2D array for Google Sheets

  } catch (e) {
    // return [['Error: ' + e.toString()]]; // Return error as a single cell
    
    Logger.log('Error fetching Prices: ' + e.toString());
  }
}

I don’t remember why I included the headings as part of the script, I was probably just getting bored to be honest.

Hopefully this is useful to someone because I’ve never had to use this again after making the one sheet.

Leave a Reply