On any web page where you have loaded Eventive Everywhere, you have access to the full Eventive client-side API using the Eventive API wrapper.
Using this API, you can do anything that a customer can do on your Eventive Native site!
The wrapper handles both platform-level authentication (API key injection) and, for customer-specific requests, login token injection (e.g. for authenticated requests to fetch a customer's tickets and passes).
Note: This integration is currently available in BETA, so changes are possible. Questions? Send us a message!
Loading the Eventive API wrapper
The Eventive API wrapper is automatically available on all pages that include Eventive Everywhere. Ensure you have followed all instructions and are able to successfully load Eventive Everywhere (test first with a simple integration, like an order tickets button).
When loaded successfully, the wrapper will be available on the window object, as window.Eventive
.
Using the Eventive API wrapper
After you have loaded Eventive Everywhere, you can call the Eventive API like so:
Eventive.request({
method: 'GET', // HTTP method verb (GET, POST, etc.)
path: 'heartbeat', // no leading slash
qs: { test: 123 }, // object of HTTP query parameters
json: { abc: 'def' } // object of JSON data to post
}).then(data => {
console.log(data);
}).catch(error => {
console.log('Eventive request failed: ' + error.message);
});
IMPORTANT: The Eventive
object will only be available in JavaScript that is included AFTER the Eventive Everywhere embed code. If you try to call Eventive.request
in code that is loaded before the embed script, you will receive an "Eventive is not defined" error.
Note that the json
parameter is only suitable for POST/PUT/PATCH
requests. GET
requests should only use qs
.
Authenticated requests
If you are making a request to an authentication-required resource that is specific to a particular person (e.g. loading their passes, tickets, viewing available passes for a particular event, etc.), you should use the authenticatePerson
parameter. For example, to fetch a list of the current logged-in user's tickets:
Eventive.request({
method: 'GET',
path: 'people/self/tickets',
authenticatePerson: true
}).then(({ tickets }) => {
console.log('tickets: ', tickets);
}).catch(error => {
console.log('Error fetching tickets: ' + error.message);
});
Logged-in status & ready handler
If you are making authenticated requests, you will likely want to check if the user is logged in, first. There are two static utility methods you can use for this purpose:
Eventive.isLoggedIn(); // returns true / false
Eventive.getPersonDetails(); // returns person details
Note that these methods are only available after Eventive Everywhere has been fully initialized. If your code calls these methods, you should wrap it in a ready handler, like this:
Eventive.on('ready', () => {
// Eventive Everywhere has been fully initialized!
// It's safe to use login status methods now.
if (Eventive.isLoggedIn()) {
alert('Welcome to Eventive, ' +
Eventive.getPersonDetails().name);
} else {
alert('No one is logged in :(');
}
});
FAQ
How does the API wrapper handle expired/invalid authentication?
If you try to make an authenticated request and the request fails due to expired or invalid credentials, an Eventive Everywhere login window will automatically be opened.
Do I have to wrap calls to the API in a ready handler?
No, the ready handler is only required when using the static utility methods. If you are not calling the utility methods, you don't need a ready handler. In those cases, the wrapper automatically queues pending requests until Eventive Everywhere is fully initialized.
Examples
The Eventive API wrapper is still in beta, so there are limited examples available. In short, you can do anything that a public
API key is allowed to do. The best way to get an idea of request format is to open the Developer Tools on your Eventive customer-facing site and look at the XHR requests! Or just send us a message :)
Fetching a logged-in customer's passes
Eventive.on('ready', () => {
if (Eventive.isLoggedIn()) {
Eventive.request({
method: 'GET',
path: 'people/self/passes',
authenticatePerson: true
}).then(({ passes }) => {
console.log(passes);
});
}
});
Fetching a logged-in customer's tickets
Eventive.on('ready', () => {
if (Eventive.isLoggedIn()) {
Eventive.request({
method: 'GET',
path: 'people/self/tickets',
authenticatePerson: true
}).then(({ tickets }) => {
console.log(tickets);
});
}
});
Updating the name of a customer's pass
Eventive.on('ready', () => {
if (Eventive.isLoggedIn()) {
Eventive.request({
method: 'POST',
path: 'passes/<pass-id>',
authenticatePerson: true,
json: {
name: "API Test Passholder"
}
}).then(updatedPass => {
console.log(updatedPass.name);
console.log(updatedPass.updated_at);
});
}
});