What is REST API
REST (REpresentation State Transfer) API (Application Programming Interface) is a great tool to take advantage of the customization possibilities for your site. It enables communication and data exchange between your site and other applications or services using standard web protocols. REST APIs often use JSON (JavaScript Object Notation) for data interchange, which is a lightweight data format that is easy for humans to read and write and easy for machines to parse and generate.
To get you started, here are some general resources that explain how WordPress Core REST API works:
Event/Ticket REST API Endpoints
There is a lot more information about WordPress Core REST API, though for the rest of this article, we are going to focus on just the REST API for The Events Calendar events and tickets. The recipe for all TEC REST API calls starts with the same basic ingredients, called the base URL. For events, this looks like:
[your-site-URL]/wp-json/tribe/events/v1/{endpoint}
Let’s break this down further.
[your-site-URL]/ – this is the part of the request asking where we want to get information from (AKA which server).
/wp-json/tribe/events/v1 – the /wp-json is part of WP Core REST API endpoints and the other parts specify which plugin we want information from. To get all ticket routes, you would simply switch out /events for /tickets.
/{endpoint} – this optional part can add even more specificity for what information the API call returns. Check out our more in-depth documentation on available REST API endpoints for events and tickets. You can also use the /doc endpoint to see all available endpoints.
Example GET Request
Using our demo site as an example, this is what our request would look like to return all events (you can test this by putting the URI right into your browser):
GET https://demo.theeventscalendar.com/wp-json/tribe/events/v1/events
And that would return a JSON that looks something like this:
{
"events": [
{
"id": 1762,
"global_id": "demo.theeventscalendar.com?id=1762",
"global_id_lineage": [
"demo.theeventscalendar.com?id=1762"
],
"author": "2",
"status": "publish",
"date": "2022-12-01 12:36:40",
"date_utc": "2022-12-01 17:36:40",
"modified": "2023-12-19 14:00:59",
"modified_utc": "2023-12-19 19:00:59",
"url": "https://demo.theeventscalendar.com/event/hosted-dinner-with-chef-monica-geller/",
"rest_url": "https://demo.theeventscalendar.com/wp-json/tribe/events/v1/events/1762",
"title": "Hosted Dinner with Chef Monica Geller",
"description": "<p>Join Chef Monica Geller for a Hosted Dinner! She will discuss how her weight loss contributed to her wanting to be a chef all while preparing her guests a healthy, balanced meal for you to enjoy.</p>",
"excerpt": "",
"slug": "hosted-dinner-with-chef-monica-geller",
// Cut short for brevity
Query Parameter Example
If you tried putting the HTTP request URI from the last section into your browser, you can see that the response can be very long. Luckily there are a bunch of different endpoints and query parameters to explore so you can whittle down the response to exactly what you’re looking for!
For example, this is what a GET request looks like to only return tickets that have Individual Attendee Collection enabled:
GET https://demo.theeventscalendar.com/wp-json/tribe/tickets/v1/tickets?attendee_information_available=true
This will only return 2 out of the 5 ticket objects on our demo site – remove the query parameter (?attendee_information_available=true) to see all 5 ticket objects.
👋 You may notice in the JSONs returned for tickets that the attendees attribute for each ticket shows as an empty array even if you know there are attendees for that ticket. This is because further authentication is required to see that data – you can learn how to do this in this article about REST API authentication.