StubHub Partner JavaScript SDK

GETTING STARTED

 

Before you can use the JavaScript APIs, you must obtain an application key from StubHub. The key is used to verify the authenticity of the API request. Here are the steps for obtaining the key:

  1. If you don't already have a StubHub account, go to StubHub Developer Portal and create one.
  2. In the "Manage Applications" tab, register your application.
  3. In the "Subscribe to APIs" tab, select your application and click "Subscribe to All".
  4. In "Manage API Access" tab, under "Production", click Generate keys.
  5. NOTE: If the key does not work, contact your Stubhub Partner connection to obtain a valid key.

After you have obtained the key, the next step is to install the JavaScript SDK on your local system for developing your web application.

 

INSTALLING THE JAVASCRIPT SDK

 

  1. Create a .npmrc file under your project folder where the package.json file is located. Use this file to specify the repository to get this npm package.
    registry=https://registry-npmjs.stubcorp.com/nexus/repository/npm/
    strict-ssl=false
  2. Run npm install @stubhub/partner-api --save to install.

 

INITIALIZING THE STUBHUB GLOBAL OBJECT

 

When your application makes a request for information from StubHub, it uses a StubHub-specific global object. You use this global object to perform your queries for event data. Since each query (or API request) to StubHub requires authentication, you must pass in the application key when you initialize the global object. This establishes the authenticity of the global object and you do not have to pass in the application key with each subsequent request. Here is the code for initializing the StubHub global object:

var StubHubJS = require('@stubhub/partner-api');
StubHubJS.initialize({token: 'you application token here'});

 

CREATING QUERIES TO RETRIEVE EVENT DATA FROM STUBHUB

 

Before you can query the StubHub Catalog for event data, you must first create an Event Query object for retrieving the data. Here's the code for creating this object:

// Create an Event Query object
var query = new StubHubJS.Query('Event');

Then you can use the Event Query object to search for event data, like this:

// Select all fields for the query
query.select('*');

// Search for events within 10 miles of a location
var geoLocation = new StubHubJS.GeoPoint(37.7897244,-122.3947561);
query.withInMiles(geoLocation, 10);

// Search for today's events in the geographic location
query.localDate(new Date());

// Sort the results by distance in ascending order
query.sort('distance', 'asc');

// Perform the event query and display results to the console  
query.find(function(err, events){
  console.log(events);
});

To get a list of recommended performers and their upcoming events, use the RecoQuery object. Here's sample code that returns a list of sports events within a 10-mile diameter radius of a given location:

// Create the RecoQuery object
var reco = new StubHubJS.RecoQuery();

// Set the geographical location for the recommended event 
var geoLocation = new StubHubJS.GeoPoint(37.7897244,-122.3947561);
reco.withInMiles(geoLocation, 10);

// Set the geographical location for the recommended event using a QueryParam enum
StubHubJS.QueryParams.CURRENT_LOCATION_WITHIN_MILES(10).setTo(reco);

// Search only for Sports performers and their events to recommend
StubHubJS.QueryParams.SPORTS.setTo(reco);

reco.find(function(err, performers) {
  performers.forEach(function(perf) {
    var events = perf.events;
    var upcomingEventCount = perf.count;
    //...
  });
});