Getting Started with the SeatGeek API
Learn about the SeatGeek API and how to get started with it.
Introduction to the SeatGeek API
SeatGeek is an online ticket-booking platform for live events, mainly in the United States and Canada. The SeatGeek API facilitates this booking process by providing a powerful tool for filtering and fetching the vast data for live events from SeatGeek. The API, however, doesn’t support booking or buying tickets through SeatGeek.
The primary purpose of the SeatGeek API is to allow developers to build on top of it to help their users search and find events and, if required, direct those users to the SeatGeek booking page. Developers who are part of the SeatGeek partner program mainly use this API because they receive a payment if any of the directed users buy a ticket through SeatGeek.
Note: The SeatGeek API follows the RESTful API protocol and supports responses in JSON, JSONP, and XML.
API authentication
You first need authorized access when making an API call to use the services of the SeatGeek API. SeatGeek provides a client ID and secret, which allows you to get authorized access to its API.
Generate client credentials
You can get your client credentials from SeatGeek's developer platform. Follow the steps listed below to generate a client credentials:
Save credentials
Here’s how to save the client credentials that you generate throughout the course:
Click the “Edit” button in the following widget.
Paste the client ID in the
CLIENT_ID
field.Paste the app secret in the
CLIENT_SECRET
field.Click the “Save” button.
As soon as you save the value, the platform will replace it in the widget below:
// Define client ID and client application secret hereconst clientId = '{{CLIENT_ID}}';const clientSecret = '{{CLIENT_SECRET}}';// Authenticating credentials hereauthenticateCredentials(clientId, clientSecret);
Use the client credentials
You must provide the client credentials in every HTTP request you make to the API. However, you can still be authenticated if you only pass the client ID and an empty string as the client secret. There are two ways to insert client credentials inside the HTTP request. Let’s look at both of these methods.
HTTP basic authentication
One way to provide the client credentials for access authorization is by passing them in the
import fetch from 'node-fetch';// Define client ID and client application secret hereconst clientId = '{{CLIENT_ID}}';const clientSecret = '{{CLIENT_SECRET}}';// Creating a basic authentication token using client id and application secretconst basicAuthToken = Buffer.from(`${clientId}:${clientSecret}`).toString('base64');// Define Header Parameters hereconst headerParameters = {authorization: `Basic ${basicAuthToken}`,};// Setting API call optionsconst options = {method: 'GET',headers: headerParameters,};// Define endpoint url hereconst endpointUrl = new URL('https://api.seatgeek.com/2/events');// Function to make API callasync function authenticationBasicAuth() {try {const response = await fetch(endpointUrl, options);// Custom function for printing list of eventsprintResponse(response);} catch (error) {// Custom function for printing the error messageprintError(error);}}// Making API call to authenticate credentialsauthenticationBasicAuth();
Take a look at the following explanation of the code above:
Lines 4–5: We declare the
clientId
andclientSecret
variables here.Line 8: We encrypt the client credentials with the
base64
encoding and save them in thebasicAuthToken
variable.Line 12: We pass the
basicAuthToken
variable with encoded client credentials to theauthorization
header. If the client credentials are valid, SeatGeek will authenticate our request and respond with the requested data.
As a query parameter
Another way to provide the client credentials for access authorization is passing them as a string to additional query parameters called client_id
and client_secret
. Here's a code example of how to do this when making an HTTP GET request to the events endpoint in JavaScript using a query parameter:
import fetch from 'node-fetch';// Define client ID and client application secret hereconst clientId = '{{CLIENT_ID}}';const clientSecret = '{{CLIENT_SECRET}}';// Setting API call optionsconst options = {method: 'GET',};// Define Query Parameters hereconst queryParameters = new URLSearchParams({client_id: clientId,client_secret: clientSecret,});// Define endpoint url hereconst endpointUrl = new URL('https://api.seatgeek.com/2/events');endpointUrl.search = queryParameters;// Function to make API callasync function authenticationBasicAuth() {try {const response = await fetch(endpointUrl, options);// Custom function for printing the API responseprintResponse(response);} catch (error) {// Custom function for printing the error messageprintError(error);}}// Making API call to authenticate credentialsauthenticationBasicAuth();
Take a look at the following explanation of the code above:
Lines 4–5: We declare the
clientId
andclientSecret
variables here.Lines 14–15: We pass the
clientId
andclientSecret
variables to theclient_id
andclient_secret
query parameters, respectively. If the client credentials are valid, SeatGeek will authenticate our request and respond with the requested data.