{"id":1896654,"date":"2019-10-18T13:19:46","date_gmt":"2019-10-18T17:19:46","guid":{"rendered":"https:\/\/theeventscalendar.com\/knowledgebase\/introduction-to-the-events-calendar-rest-api\/"},"modified":"2024-10-10T16:59:53","modified_gmt":"2024-10-10T20:59:53","slug":"introduction-to-the-events-calendar-rest-api","status":"publish","type":"post","link":"https:\/\/theeventscalendar.com\/knowledgebase\/introduction-to-the-events-calendar-rest-api\/","title":{"rendered":"The Events Calendar REST API Reference"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p class=\"has-theme-palette-8-background-color has-background\">\ud83d\udc4b This article was originally written in 2017 and some information is outdated. We are currently working to build an updated REST API guide &#8211; please see <a href=\"https:\/\/theeventscalendar.com\/knowledgebase\/event-ticket-rest-api-basics\/\" target=\"_blank\" rel=\"noreferrer noopener\">REST API Basics<\/a>, <a href=\"https:\/\/theeventscalendar.com\/knowledgebase\/rest-api-authentication\/\" target=\"_blank\" rel=\"noreferrer noopener\">REST API authentication<\/a>, and <a href=\"https:\/\/theeventscalendar.com\/knowledgebase\/troubleshooting-rest-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">REST API Troubleshooting<\/a>. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-a-rest-api\">What is a REST API, again?<\/h2>\n\n\n\n<p>If you work at all with the web, you will have probably heard of many &#8220;REST APIs&#8221;, particularly the <a href=\"https:\/\/developer.wordpress.org\/rest-api\/\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress REST API<\/a>. Any article dealing with a REST API devotes its beginning to explaining <strong>what<\/strong> a REST API is. While we follow that pattern, we&#8217;ll try to be as concise as possible.<\/p>\n\n\n\n<p>The &#8220;API&#8221; acronym stands for &#8220;Application Programming Interface&#8221;. In layman&#8217;s terms, it means the tools and controls (the <em>Interface<\/em>) the server (typically a website) makes available to the client (the Application in API &#8211; typically a browser, app, or other website) for accessing data. Our main concern with APIs typically involves the format the data is exchanged in &#8211; &#8220;how do we use this?&#8221;<\/p>\n\n\n\n<p>The &#8220;REST&#8221; acronym stands for &#8220;REpresentational State Transfer&#8221; which means that the state of the transaction between a client and the server providing a RESTful API is wholly contained in the response the client receives, so &#8220;WYSIWYG&#8221; for data. HTTP protocol-based communications (what a browser uses to &#8220;get stuff&#8221; from the web) are considered to be the only domain where it makes sense to talk about REST APIs. We use the term <strong>&#8220;consume&#8221;<\/strong> to describe when a client uses an API (the Transfer).<\/p>\n\n\n\n<p>&#8220;State&#8221; is the representation of how a client got what it currently holds: if you have $5 in your pocket and a shop receipt saying you paid for a $5 meal with a $10 bill, you know what you have ($5) and how you got there (spent $5 and got $5 in change). If all you had was the $5 bill, the scenarios leading to that might include you winning the lottery, losing it all to tricky raccoons, and finding a $5 bill on the ground.<\/p>\n\n\n\n<p>So, for an API to be &#8220;RESTful&#8221;, said API should not require clients <strong>consuming<\/strong> it to keep track of a &#8220;state&#8221; and make full use of HTTP methods.<\/p>\n\n\n\n<p>HTTP is a protocol, the one you use to commonly access a site using a URL like <strong>http:\/\/how-not-to-get-scammed-by-raccoons.org<\/strong>. It provides ways to do what you need to do on the web. Commonly you use the <samp>GET<\/samp> method to retrieve data from websites. In the case above, the HTTP request would look like this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nGET http:\/\/how-not-to-get-scammed-by-raccoons.org\/index.php\n<\/pre><\/div>\n\n\n<p>But <samp>GET<\/samp> is not the only existing HTTP method. When you submit a form, you are usually making a <samp>POST<\/samp> request to a URL. That request represents your intent to <strong>send<\/strong> data to the site instead of <strong>receiving<\/strong> data from it. When completing a login form, you press the submit button in the form, and the browser would make a request like this:<\/p>\n\n\n\n<p><code>POST http:\/\/how-not-to-get-scammed-by-raccoons.org\/login.php<br>\nuser=luca&amp;password=secret<\/code><\/p>\n\n\n\n<p>Since you are <strong>sending<\/strong> something, the <samp>user=luca&amp;password=secret<\/samp> string represents what you are sending to the server. The syntax above does not correspond to any particular API and is merely for the purposes of this article&#8211;do not use that in your code, or raccoons will invade your home!<\/p>\n\n\n\n<p><samp>GET<\/samp> and <samp>POST<\/samp> are the most widely used HTTP methods, but there are more: <samp>DELETE<\/samp> is used to remove stuff from the server, <samp>PATCH<\/samp> or <samp>PUT<\/samp> are commonly used to edit data on the server, and <samp>HEAD<\/samp> and <samp>OPTIONS<\/samp> are used to fetch information about the server.<\/p>\n\n\n\n<p>When an API makes full and correct use of the methods above, it is then considered &#8220;RESTful&#8221;. If I wanted to update my password on the site, I could use:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">PUT http:\/\/how-not-to-get-scammed-by-raccoons.org\/api\/users\/luca\n    password=new-secret<\/pre>\n\n\n\n<p>Notice I&#8217;m now using a different URL to perform the required operation, one that ends in <samp>\/api\/users\/luca<\/samp>. This could be translated as &#8220;call the <samp>api<\/samp> on <samp>http:\/\/how-not-to-get-scammed-by-raccoons.org<\/samp>: we need to update the details for one of the <samp>users<\/samp>, <samp>luca<\/samp> is the name, and set the <samp>password<\/samp> to <samp>new-secret<\/samp>&#8220;.<\/p>\n\n\n\n<p>In technical terms, <samp>\/api<\/samp> is the site&#8217;s REST API <strong>root path<\/strong>, <samp>\/api\/users<\/samp> is an <strong>endpoint<\/strong> provided by the API, and <samp>luca<\/samp> is a <strong>parameter<\/strong> of the specific call.<\/p>\n\n\n\n<p>If we wanted to remove my user from the site, we would issue this request to the server:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">DELETE http:\/\/how-not-to-get-scammed-by-raccoons.org\/api\/users\/luca<\/pre>\n\n\n\n<p>Now you know why a typical WordPress &#8220;Trash&#8221; link, which employs URLs such as <samp>http:\/\/tribe.localhost\/wp-admin\/post.php?post=6&amp;action=trash&amp;_wpnonce=25a5cdc0ba<\/samp>, is not RESTful: you are deleting something using the HTTP <samp>GET<\/samp> method.<\/p>\n\n\n\n<p>Reading the examples, it&#8217;s clear that the site might authorize <em>anyone<\/em> to make <samp>GET<\/samp> requests, but it would probably impose limits (in the form of authentication requirements) on performing operations like adding, updating and deleting a user. Or any kind of data, really. Almost any REST API, the WordPress and The Events Calendar APIs being no exception, will make full use of authorization to allow or not allow a user to perform an action. There are many ways to authenticate a user&#8211;for the time being, just keep the idea in mind.<\/p>\n\n\n\n<p>The last piece of information you need to fully qualify as a REST API expert, is the notion of HTTP <em>response codes<\/em>. These are numbers the server will use to tell the client what happened in response to a certain request. You are probably familiar with some: <samp>404<\/samp> means what you were looking for was not found, <samp>403<\/samp> means you are not authorized to do what you tried to do, <samp>500<\/samp> means an internal error happened on the server, and so on. Feast your eyes on the full list of status codes <a href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_HTTP_status_codes\">here<\/a>, and get ready to explore The Events Calendar REST API.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-can-we-use-it\">A REST API for The Events Calendar: how can we use it?<\/h2>\n\n\n\n<p>We built The Events Calendar REST API to allow our users and ourselves to <strong>consume<\/strong> and manage events created with The Events Calendar <strong>from anywhere<\/strong>. In its most basic form, a REST API separates the content from its presentation, freeing developers and users from the unbreakable paradigm of a WordPress site and a WordPress theme.<\/p>\n\n\n\n<p>&#8220;Anywhere&#8221; is a big concept, so here are some examples:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We are updating the administration UI used in The Events Calendar to manage events using the REST API in place of the standard WordPress flow. This means more responsive UI, no more page reloads, and faster iterations.<\/li>\n\n\n\n<li>Themes will be able to access events, venues, and organizers&#8217; data without the need to use the plugin PHP functions, and developers will be able to present that data to users in any way they want. Creating new views, widgets, and calendars will become easier than ever.<\/li>\n\n\n\n<li>Sites not using PHP or WordPress will be able to use a WordPress installation as a content management system to manage events, venues, and organizers while the site&#8217;s front-end is maintained in a preferred language.<\/li>\n\n\n\n<li>Android, iOS, and other mobile application developers will be able to use a WordPress backend to manage events and present the same information to different users on different platforms, with &#8220;thin&#8221; clients, in a way that fits their target audience and platform.<\/li>\n<\/ul>\n\n\n\n<p>Since The Events Calendar REST API is built on top of the <a href=\"https:\/\/developer.wordpress.org\/rest-api\/\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress REST API<\/a> it inherits its excellent code, robustness, and security.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"a-first-example\">A first example<\/h2>\n\n\n\n<p>Now that we&#8217;ve sung the praises of The Events Calendar REST API, it&#8217;s time to see it in action!<\/p>\n\n\n\n<p>The Events Calendar REST API is free and bundled with The Events Calendar plugin. It is PHP 5.2 compatible and requires WordPress 4.5 or above. Once you have installed the latest version of The Events Calendar, simply activate, and you&#8217;re ready to get started.<\/p>\n\n\n\n<p>In the following examples, we&#8217;ll assume the site on which The Events Calendar REST API is active can be reached at <samp>http:\/\/tribe.localhost<\/samp>&#8211;so keep that in mind.<\/p>\n\n\n\n<p>Once The Events Calendar is active, we&#8217;ll create an event, set its details, publish it, and preview it in the browser:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2017\/09\/example-event-1-665x492.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>This is the familiar look of an event in the context of the Twenty Seventeen theme. Let&#8217;s now head, using a browser, to the address <samp>http:\/\/tribe.localhost\/wp-json\/tribe\/events\/v1\/events<\/samp>:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2017\/09\/rest-example-events-665x280.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>Uhm\u2026 not that nice. But wait: that&#8217;s <strong>the essence<\/strong> of what The Events Calendar REST API does: providing the raw data about the event without all the presentation stuff surrounding it.<\/p>\n\n\n\n<p>Here is the response in a pretty format:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n{\n    &quot;events&quot;: &#x5B;{\n        &quot;id&quot;: 6,\n        &quot;global_id&quot;: &quot;tribe.localhost?id=6&quot;,\n        &quot;global_id_lineage&quot;: &#x5B;\n            &quot;tribe.localhost?id=6&quot;\n        ],\n        &quot;author&quot;: &quot;1&quot;,\n        &quot;status&quot;: &quot;publish&quot;,\n        &quot;date&quot;: &quot;2017-09-21 11:57:52&quot;,\n        &quot;date_utc&quot;: &quot;2017-09-21 11:57:52&quot;,\n        &quot;modified&quot;: &quot;2017-09-21 12:03:35&quot;,\n        &quot;modified_utc&quot;: &quot;2017-09-21 12:03:35&quot;,\n        &quot;url&quot;: &quot;http:\/\/tribe.localhost\/event\/example-event-1\/&quot;,\n        &quot;rest_url&quot;: &quot;http:\/\/tribe.localhost\/wp-json\/tribe\/events\/v1\/events\/6&quot;,\n        &quot;title&quot;: &quot;REST Event 1&quot;,\n        &quot;description&quot;: &quot;Example content&quot;,\n        &quot;excerpt&quot;: &quot;&quot;,\n        &quot;image&quot;: {\n            &quot;url&quot;: &quot;http:\/\/tribe.localhost\/wp-content\/uploads\/2017\/09\/raccoon.jpg&quot;,\n            &quot;id&quot;: &quot;8&quot;,\n            &quot;extension&quot;: &quot;jpg&quot;,\n            &quot;width&quot;: 220,\n            &quot;height&quot;: 147,\n            &quot;sizes&quot;: {\n                &quot;thumbnail&quot;: {\n                    &quot;width&quot;: 150,\n                    &quot;height&quot;: 147,\n                    &quot;mime-type&quot;: &quot;image\/jpeg&quot;,\n                    &quot;url&quot;: &quot;http:\/\/tribe.localhost\/wp-content\/uploads\/2017\/09\/raccoon-150x147.jpg&quot;\n                }\n            }\n        },\n        &quot;all_day&quot;: false,\n        &quot;start_date&quot;: &quot;2017-09-21 08:00:00&quot;,\n        &quot;start_date_details&quot;: {\n            &quot;year&quot;: &quot;2017&quot;,\n            &quot;month&quot;: &quot;09&quot;,\n            &quot;day&quot;: &quot;21&quot;,\n            &quot;hour&quot;: &quot;08&quot;,\n            &quot;minutes&quot;: &quot;00&quot;,\n            &quot;seconds&quot;: &quot;00&quot;\n        },\n        &quot;end_date&quot;: &quot;2017-09-21 17:00:00&quot;,\n        &quot;end_date_details&quot;: {\n            &quot;year&quot;: &quot;2017&quot;,\n            &quot;month&quot;: &quot;09&quot;,\n            &quot;day&quot;: &quot;21&quot;,\n            &quot;hour&quot;: &quot;17&quot;,\n            &quot;minutes&quot;: &quot;00&quot;,\n            &quot;seconds&quot;: &quot;00&quot;\n        },\n        &quot;utc_start_date&quot;: &quot;2017-09-21 08:00:00&quot;,\n        &quot;utc_start_date_details&quot;: {\n            &quot;year&quot;: &quot;2017&quot;,\n            &quot;month&quot;: &quot;09&quot;,\n            &quot;day&quot;: &quot;21&quot;,\n            &quot;hour&quot;: &quot;08&quot;,\n            &quot;minutes&quot;: &quot;00&quot;,\n            &quot;seconds&quot;: &quot;00&quot;\n        },\n        &quot;utc_end_date&quot;: &quot;2017-09-21 17:00:00&quot;,\n        &quot;utc_end_date_details&quot;: {\n            &quot;year&quot;: &quot;2017&quot;,\n            &quot;month&quot;: &quot;09&quot;,\n            &quot;day&quot;: &quot;21&quot;,\n            &quot;hour&quot;: &quot;17&quot;,\n            &quot;minutes&quot;: &quot;00&quot;,\n            &quot;seconds&quot;: &quot;00&quot;\n        },\n        &quot;timezone&quot;: &quot;UTC+0&quot;,\n        &quot;timezone_abbr&quot;: &quot;&quot;,\n        &quot;cost&quot;: &quot;$5&quot;,\n        &quot;cost_details&quot;: {\n            &quot;currency_symbol&quot;: &quot;$&quot;,\n            &quot;currency_position&quot;: &quot;prefix&quot;,\n            &quot;values&quot;: &#x5B;&quot;5&quot;]\n        },\n        &quot;website&quot;: &quot;http:\/\/raccoons-ate-my-neighbour.com&quot;,\n        &quot;show_map&quot;: false,\n        &quot;show_map_link&quot;: false,\n        &quot;hide_from_listings&quot;: false,\n        &quot;sticky&quot;: false,\n        &quot;featured&quot;: false,\n        &quot;categories&quot;: &#x5B;{\n            &quot;name&quot;: &quot;rest-stuff&quot;,\n            &quot;slug&quot;: &quot;rest-stuff&quot;,\n            &quot;term_group&quot;: 0,\n            &quot;term_taxonomy_id&quot;: 2,\n            &quot;taxonomy&quot;: &quot;tribe_events_cat&quot;,\n            &quot;description&quot;: &quot;&quot;,\n            &quot;parent&quot;: 0,\n            &quot;count&quot;: 1,\n            &quot;filter&quot;: &quot;raw&quot;,\n            &quot;id&quot;: 2,\n            &quot;urls&quot;: {\n                &quot;self&quot;: &quot;http:\/\/tribe.localhost\/wp-json\/tribe\/events\/v1\/categories\/2&quot;,\n                &quot;collection&quot;: &quot;http:\/\/tribe.localhost\/wp-json\/tribe\/events\/v1\/categories&quot;\n            }\n        }],\n        &quot;tags&quot;: &#x5B;{\n            &quot;name&quot;: &quot;example&quot;,\n            &quot;slug&quot;: &quot;example&quot;,\n            &quot;term_group&quot;: 0,\n            &quot;term_taxonomy_id&quot;: 3,\n            &quot;taxonomy&quot;: &quot;post_tag&quot;,\n            &quot;description&quot;: &quot;&quot;,\n            &quot;parent&quot;: 0,\n            &quot;count&quot;: 1,\n            &quot;filter&quot;: &quot;raw&quot;,\n            &quot;id&quot;: 3,\n            &quot;urls&quot;: {\n                &quot;self&quot;: &quot;http:\/\/tribe.localhost\/wp-json\/tribe\/events\/v1\/tags\/3&quot;,\n                &quot;collection&quot;: &quot;http:\/\/tribe.localhost\/wp-json\/tribe\/events\/v1\/tags&quot;\n            }\n        }, {\n            &quot;name&quot;: &quot;raccoon&quot;,\n            &quot;slug&quot;: &quot;raccoon&quot;,\n            &quot;term_group&quot;: 0,\n            &quot;term_taxonomy_id&quot;: 4,\n            &quot;taxonomy&quot;: &quot;post_tag&quot;,\n            &quot;description&quot;: &quot;&quot;,\n            &quot;parent&quot;: 0,\n            &quot;count&quot;: 1,\n            &quot;filter&quot;: &quot;raw&quot;,\n            &quot;id&quot;: 4,\n            &quot;urls&quot;: {\n                &quot;self&quot;: &quot;http:\/\/tribe.localhost\/wp-json\/tribe\/events\/v1\/tags\/4&quot;,\n                &quot;collection&quot;: &quot;http:\/\/tribe.localhost\/wp-json\/tribe\/events\/v1\/tags&quot;\n            }\n        }],\n        &quot;venue&quot;: {\n            &quot;id&quot;: 10,\n            &quot;author&quot;: &quot;1&quot;,\n            &quot;status&quot;: &quot;publish&quot;,\n            &quot;date&quot;: &quot;2017-09-21 12:00:59&quot;,\n            &quot;date_utc&quot;: &quot;2017-09-21 12:00:59&quot;,\n            &quot;modified&quot;: &quot;2017-09-21 12:00:59&quot;,\n            &quot;modified_utc&quot;: &quot;2017-09-21 12:00:59&quot;,\n            &quot;url&quot;: &quot;http:\/\/tribe.localhost\/venue\/raccoon-org\/&quot;,\n            &quot;venue&quot;: &quot;raccoon Org&quot;,\n            &quot;description&quot;: &quot;Venue Description&quot;,\n            &quot;address&quot;: &quot;123, raccoon Ave.&quot;,\n            &quot;city&quot;: &quot;Raccon City&quot;,\n            &quot;country&quot;: &quot;United States&quot;,\n            &quot;province&quot;: &quot;raccoon County&quot;,\n            &quot;state&quot;: &quot;NH&quot;,\n            &quot;zip&quot;: &quot;12345&quot;,\n            &quot;phone&quot;: &quot;+112341234&quot;,\n            &quot;website&quot;: &quot;http:\/\/raccoons.org&quot;,\n            &quot;stateprovince&quot;: &quot;NH&quot;,\n            &quot;show_map&quot;: true,\n            &quot;show_map_link&quot;: true,\n            &quot;global_id&quot;: &quot;tribe.localhost?id=10&quot;,\n            &quot;global_id_lineage&quot;: &#x5B;&quot;tribe.localhost?id=10&quot;]\n        },\n        &quot;organizer&quot;: &#x5B;{\n            &quot;id&quot;: 11,\n            &quot;author&quot;: &quot;1&quot;,\n            &quot;status&quot;: &quot;publish&quot;,\n            &quot;date&quot;: &quot;2017-09-21 12:01:48&quot;,\n            &quot;date_utc&quot;: &quot;2017-09-21 12:01:48&quot;,\n            &quot;modified&quot;: &quot;2017-09-21 12:01:48&quot;,\n            &quot;modified_utc&quot;: &quot;2017-09-21 12:01:48&quot;,\n            &quot;url&quot;: &quot;http:\/\/tribe.localhost\/organizer\/a-first-raccoon\/&quot;,\n            &quot;organizer&quot;: &quot;A first raccoon&quot;,\n            &quot;description&quot;: &quot;Shy but packing a lot of punch.&quot;,\n            &quot;phone&quot;: &quot;+1233434234&quot;,\n            &quot;website&quot;: &quot;http:\/\/first-raccoon.com&quot;,\n            &quot;email&quot;: &quot;first@raccoon.com&quot;,\n            &quot;global_id&quot;: &quot;tribe.localhost?id=11&quot;,\n            &quot;global_id_lineage&quot;: &#x5B;&quot;tribe.localhost?id=11&quot;]\n        }, {\n            &quot;id&quot;: 12,\n            &quot;author&quot;: &quot;1&quot;,\n            &quot;status&quot;: &quot;publish&quot;,\n            &quot;date&quot;: &quot;2017-09-21 12:02:43&quot;,\n            &quot;date_utc&quot;: &quot;2017-09-21 12:02:43&quot;,\n            &quot;modified&quot;: &quot;2017-09-21 12:02:43&quot;,\n            &quot;modified_utc&quot;: &quot;2017-09-21 12:02:43&quot;,\n            &quot;url&quot;: &quot;http:\/\/tribe.localhost\/organizer\/a-second-raccoon\/&quot;,\n            &quot;organizer&quot;: &quot;A second raccoon&quot;,\n            &quot;description&quot;: &quot;Gentle and deadly.&quot;,\n            &quot;phone&quot;: &quot;+134473847&quot;,\n            &quot;website&quot;: &quot;http:\/\/raccoon-for-me.com&quot;,\n            &quot;email&quot;: &quot;racc00n@raccoon.for-me.com&quot;,\n            &quot;global_id&quot;: &quot;tribe.localhost?id=12&quot;,\n            &quot;global_id_lineage&quot;: &#x5B;&quot;tribe.localhost?id=12&quot;]\n        }]\n    }],\n    &quot;rest_url&quot;: &quot;http:\/\/tribe.localhost\/wp-json\/tribe\/events\/v1\/events\/?page=1&amp;amp;per_page=10&amp;amp;start_date=2017-09-21 01:59:00&amp;amp;end_date=2019-09-21 13:06:27&quot;,\n    &quot;total&quot;: 1,\n    &quot;total_pages&quot;: 1\n}\n\n<\/pre><\/div>\n\n\n<p>This time, I&#8217;ve specified some parameters for my request:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><samp>per_page=2<\/samp> which means &#8220;show me two events per page&#8221;<\/li>\n\n\n\n<li><samp>page=2<\/samp> which means &#8220;show me the second page&#8221;<\/li>\n<\/ul>\n\n\n\n<p>The REST API is using those parameters to narrow down the query.<br>The word &#8220;query&#8221; should sound familiar to WordPress developers, and that&#8217;s because many of the WordPress and The Events Calendar REST API parameters share a name with those used <a href=\"https:\/\/codex.wordpress.org\/Class_Reference\/WP_Query\">in a <samp>WP_Query<\/samp><\/a> object. Some of those parameters will be set to a default value by the REST API, and that explains why the <samp>rest_url<\/samp> in the data does not look exactly like the one we typed.<\/p>\n\n\n\n<p>What if we only want to get a single event and not all of them?<br>It&#8217;s sufficient to pass the event post ID as a path parameter in the URL, like this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nGET http:\/\/tribe.localhost\/wp-json\/tribe\/events\/v1\/events\/6\n<\/pre><\/div>\n\n\n<p>The data returned is identical to the one shown above but for that specific event only (content removed for brevity):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n{\n    &quot;id&quot;: 6,\n    &quot;author&quot;: &quot;1&quot;,\n    &quot;title&quot;: &quot;REST Event 1&quot;,\n    &quot;description&quot;: &quot;Example content&quot; \n}\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"modifying-the-response\">Modifying the response<\/h2>\n\n\n\n<p>So far, we&#8217;ve seen the stock response format from The Events Calendar REST API, but what if we want to change the contents of that response?<br>As WordPress developers managing a site dedicated to victims of scams perpetrated by raccoons, we might provide an educated guess about how much an event &#8220;looks suspicious&#8221; to us. We do that by allowing the site editors to set a <samp>_raccoon_suspect_level<\/samp> custom field (aka &#8220;meta field&#8221;) value ranging from <samp>1<\/samp> to <samp>5<\/samp>. As the good and honest developers that we are, we want that value to show up in the REST API response: we can use the <samp>tribe_rest_single_event_data<\/samp> filter to do exactly that.<\/p>\n\n\n\n<p>The following code should live in a plugin or in the current theme&#8217;s <samp>functions.php<\/samp> file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nadd_filter( &#039;tribe_rest_single_event_data&#039;, &#039;raccoon_add_suspect_level&#039; );\n\nfunction raccoon_add_suspect_level( array $event_data ) {\n    $event_id = $event_data&#x5B;&#039;id&#039;];\n\n    $level = get_post_meta( $event_id, &#039;_raccoon_suspect_level&#039;, true );\n\n    if ( empty( $level ) ) {\n        \/\/ let&#039;s be wary...\n        $level = &#039;4&#039;;\n    }\n\n    $event_data&#x5B;&#039;raccoon_supect_level&#039;] = $level;\n\n    return $event_data;\n}\n\n<\/pre><\/div>\n\n\n<p>And see that pop up in the response (content removed for brevity):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n{\n    &quot;id&quot;: 6,\n    &quot;author&quot;: &quot;1&quot;,\n    &quot;status&quot;: &quot;publish&quot;,\n    &quot;title&quot;: &quot;REST Event 1&quot;,\n    &quot;raccoon_supect_level&quot;: &quot;5&quot;,\n    description: &quot;Example content &quot;,\n    &quot;json_ld&quot;: {\n        &quot;@context &quot;: &quot;http: \/\/schema.org&quot;,\n        &quot;@type&quot;: &quot;Event&quot;,\n        &quot;name&quot;: &quot;REST Event 1&quot;,\n        &quot;raccoon_supect_level&quot;: &quot;1&quot;,\n        &quot;description&quot;: &quot;Example content &quot;,\n        &quot;image &quot;: &quot;http: \/\/tribe.localhost\/wp-content\/uploads\/2017\/09\/raccoon.jpg&quot;,\n        &quot;url&quot;: &quot;http:\/\/tribe.localhost\/event\/example-event-1\/&quot;,\n        &quot;startDate&quot;: &quot;2017-09-21 08:00:00&quot;,\n        &quot;endDate&quot;: &quot;2017-09-21 17:00:00&quot;,\n        &quot;location&quot;: {\n            &quot;@type&quot;: &quot;Place&quot;,\n            &quot;name&quot;: &quot;raccoon Org&quot;,\n            &quot;description&quot;: &quot;Venue Description&quot;,\n            &quot;url&quot;: false,\n            &quot;address&quot;: {\n                &quot;@type&quot;: &quot;PostalAddress&quot;,\n                &quot;streetAddress&quot;: &quot;123, raccoon Ave.&quot;,\n                &quot;addressLocality&quot;: &quot;Raccoon City&quot;,\n                &quot;addressRegion&quot;: &quot;NH&quot;,\n                &quot;postalCode&quot;: &quot;12345&quot;,\n                &quot;addressCountry&quot;: &quot;United States&quot;\n            },\n            &quot;telephone&quot;: &quot;+112341234&quot;,\n            &quot;sameAs&quot;: &quot;http:\/\/raccoons.org&quot;\n        },\n        &quot;organizer&quot;: {\n            &quot;@type&quot;: &quot;Person&quot;,\n            &quot;name&quot;: &quot;A first raccoon&quot;,\n            &quot;description&quot;: &quot;Shy but packing a lot of punch.&quot;,\n            &quot;url&quot;: false,\n            &quot;telephone&quot;: &quot;+1233434234&quot;,\n            &quot;email&quot;: &quot;one@first-raccoon.com&quot;,\n            &quot;sameAs&quot;: &quot;http:\/\/first-raccoon.com&quot;\n        },\n        &quot;offers&quot;: {\n            &quot;@type&quot;: &quot;Offer&quot;,\n            &quot;price&quot;: &quot;5&quot;,\n            &quot;url&quot;: &quot;http:\/\/tribe.localhost\/event\/example-event-1\/&quot;\n        }\n    },\n    &quot;raccoon_supect_level&quot;: &quot;5&quot;\n}\n\n<\/pre><\/div>\n\n\n<p>But wait for a second: what&#8217;s that <samp>json_ld<\/samp> stuff in the response?<br>We haven&#8217;t shown it before, but, when grabbing a single event, the REST API will also provide <a href=\"http:\/\/json-ld.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">the JSON LD data<\/a> for the event. Again. Information. A <em>lot<\/em> of it.<br>But what if you don&#8217;t need that piece of information and would like to remove it from the response?<br>The same principle applies&#8211;filter the response data and remove it.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nadd_filter( &#039;tribe_rest_single_event_data&#039;, &#039;raccoon_remove_json_ld_data&#039; );\n\nfunction raccoon_remove_json_ld_data( array $event_data ) {\n    unset( $event_data&#x5B;&#039;json_ld&#039;] );\n\n    return $event_data;\n}\n<\/pre><\/div>\n\n\n<p>The code is full of filters you can use to customize your responses, not only for events but for venues and organizers as well. So we&#8217;re pretty confident there will always be a way for you to make it work the way you want it to. Take a look around in the <samp>src\/Tribe\/REST\/V1<\/samp> folder to begin with.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"swagger-io-documentation\">A living Swagger.io documentation<\/h2>\n\n\n\n<p>There is so much you can do with The Events Calendar REST API that you might get lost. Figuratively speaking, of course.<\/p>\n\n\n\n<p>Instead of having to parse page after page of out-of-date documentation, Post-It notes, and Slack messages, The Events Calendar REST API comes with a documentation endpoint you can hit any time you&#8217;re lost. You can find it at <samp>\/wp-json\/tribe\/events\/v1\/doc<\/samp>.<\/p>\n\n\n\n<p>Hitting the endpoint in a browser (<samp>http:\/\/tribe.localhost\/wp-json\/tribe\/events\/v1\/doc<\/samp> in our example) will provide&#8211;you probably guessed it&#8211;a JSON format object detailing all the functionalities available on the REST API. An insanely large amount of content has been omitted for your comfort:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n{\n    &quot;swagger&quot;: &quot;2.0&quot;,\n    &quot;info&quot;: {\n        &quot;version&quot;: &quot;1.0.0&quot;,\n        &quot;title&quot;: &quot;The Events Calendar REST API&quot;,\n        &quot;description&quot;: &quot;The Events Calendar REST API allows accessing upcoming events information easily and conveniently.&quot;\n    },\n    &quot;host&quot;: &quot;tribe.localhost&quot;,\n    &quot;basePath&quot;: &quot;\/wp-json\/tribe\/events\/v1\/&quot;,\n    &quot;schemes&quot;: &#x5B;\n        &quot;http&quot;\n    ],\n    &quot;consumes&quot;: &#x5B;\n        &quot;application\/json&quot;\n    ],\n    &quot;produces&quot;: &#x5B;\n        &quot;application\/json&quot;\n    ],\n    &quot;paths&quot;: {\n        &quot;\/doc&quot;: {\n            &quot;get&quot;: {\n                &quot;responses&quot;: {\n                    &quot;200&quot;: {\n                        &quot;description&quot;: &quot;Returns the documentation for The Events Calendar REST API in Swagger consumable format.&quot;\n                    }\n                }\n            }\n        },\n        &quot;\/events&quot;: {\n            &quot;get&quot;: {\n                &quot;parameters&quot;: &#x5B;\n                    {\n                        &quot;in&quot;: &quot;query&quot;,\n                        &quot;type&quot;: &quot;integer&quot;,\n                        &quot;description&quot;: &quot;The archive page to return&quot;,\n                        &quot;required&quot;: false,\n                        &quot;default&quot;: 1,\n                        &quot;name&quot;: &quot;page&quot;\n                    },\n                    {\n                        &quot;in&quot;: &quot;query&quot;,\n                        &quot;type&quot;: &quot;integer&quot;,\n                        &quot;description&quot;: &quot;The number of events to return on each page&quot;,\n                        &quot;required&quot;: false,\n                        &quot;default&quot;: &quot;10&quot;,\n                        &quot;name&quot;: &quot;per_page&quot;\n                    },\n                }\n            }\n        }\n    }\n}\n<\/pre><\/div>\n\n\n<p>Why a JSON object?<\/p>\n\n\n\n<p>That entry at the beginning of the response saying <samp>&#8220;swagger&#8221;: &#8220;2.0&#8221;<\/samp> tells you that The Events Calendar REST API documentation comes in <a href=\"https:\/\/swagger.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">Swagger.io<\/a> format. If you copy and paste the whole response into the <a href=\"https:\/\/editor.swagger.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">Swagger.io API editor<\/a>, it will be converted into easily readable documentation:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2017\/09\/swagger-output-665x408.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2017\/09\/swagger-output-2-665x408.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>This has several advantages:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The documentation is the code itself. As we, or you, update the code, the documentation will be updated with it.<\/li>\n\n\n\n<li>You can modify the documentation while modifying the code: no more documentation in one place and code in the other.<\/li>\n\n\n\n<li>You can customize The Events Calendar REST API to your liking and host a dedicated documentation site.<\/li>\n\n\n\n<li>It&#8217;s really cool. \ud83d\ude42<\/li>\n<\/ol>\n\n\n\n<p>What else? Oh, right&#8211;since we provide documentation in Swagger.io format, <strong>you can generate client applications for The Events Calendar REST API from the Swagger.io editor<\/strong>. With one click.<\/p>\n\n\n\n<p>Since The Events Calendar REST API documentation is generated by WordPress code, you can filter that too. What about documenting that <samp>raccoon_suspect_level<\/samp> field from before?<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nadd_filter( &#039;tribe_rest_swagger_event_documentation&#039;, &#039;raccoon_document_suspect_level&#039; );\n\nfunction raccoon_document_suspect_level( array $documentation ) {\n    $documentation&#x5B;&#039;properties&#039;]&#x5B;&#039;raccoon_suspect_level&#039;] = array(\n        &#039;type&#039;        =&gt; &#039;integer&#039;,\n        &#039;description&#039; =&gt; __( &#039;How much the event looks like a raccoon scam in a 1 to 5 range&#039;, &#039;raccoon&#039; ),\n    );\n\n    return $documentation;\n}\n<\/pre><\/div>\n\n\n<p>And here is the field in the Swagger.io output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2017\/09\/racoon-documentation-665x408.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"javascript-example-authentication\">A JavaScript example of authentication<\/h2>\n\n\n\n<p>So far we&#8217;ve limited our request to what is publicly available on the site. By default, The Events Calendar REST API will show events in the same way the plugin would: if you are a visitor, a user who is not logged in, or a user with subscriber-level access, you will be shown public events, venues, or organizers only. If you are an editor up to an administrator, you will be shown private and draft posts, too.<\/p>\n\n\n\n<p>Let&#8217;s try and see an example of how basic, cookie-based authentication would work in the context of the crappiest theme ever.<\/p>\n\n\n\n<p>The way WordPress knows &#8220;who you are&#8221;, as a user, is by using cookies and <a href=\"https:\/\/codex.wordpress.org\/WordPress_Nonces\">&#8220;nonces&#8221;<\/a>. When we want to perform operations reserved for logged-in users with specific roles, WordPress will print on the page a string (a <strong>nonce<\/strong>) that has been generated using the information in the authentication cookies and a specific action. In the &#8220;Trash&#8221; link shown in the first paragraph\u2026<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nhttp:\/\/tribe.localhost\/wp-admin\/post.php?post=6&amp;amp;action=trash&amp;amp;_wpnonce=25a5cdc0ba\n<\/pre><\/div>\n\n\n<p>\u2026 I&#8217;m asking WordPress to delete an event with ID <samp>6<\/samp>, the action is <samp>trash<\/samp>, and the nonce is <samp>25a5cdc0ba<\/samp>. This nonce string can only be used by me to trash that post.<\/p>\n\n\n\n<p>The Events Calendar REST API will support (extending the WordPress REST API) cookie-based authentication out of the box, but it&#8217;s ready to support any <a href=\"https:\/\/developer.wordpress.org\/rest-api\/using-the-rest-api\/authentication\/\" target=\"_blank\" rel=\"noopener noreferrer\">authentication method supported by WordPress REST API<\/a> by extension. We did not reinvent the wheel.<\/p>\n\n\n\n<p>With that in mind, let&#8217;s write a JavaScript-based theme that will show 3 upcoming events to the user on the site&#8217;s index page. We&#8217;re creating a Twenty Seventeen child theme to piggy-back on the good stuff.<\/p>\n\n\n\n<p>In the theme&#8217;s <samp>functions.php<\/samp> file, besides loading the parent theme scripts and styles, we&#8217;ll load the child theme script, <samp>\/js\/rest-theme.js<\/samp>, and the nonce we need:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ file functions.php\n\nadd_action( &#039;wp_enqueue_scripts&#039;, &#039;twentyseventeen_parent_theme_enqueue_styles&#039; );\n\nfunction twentyseventeen_parent_theme_enqueue_styles() {\n    wp_enqueue_style( &#039;twentyseventeen-style&#039;, get_template_directory_uri() . &#039;\/style.css&#039; );\n    wp_enqueue_style( &#039;rest-style&#039;,\n        get_stylesheet_directory_uri() . &#039;\/style.css&#039;,\n        array( &#039;twentyseventeen-style&#039; )\n    );\n    \n    \/\/ enqueue the theme script...\n    wp_enqueue_script( &#039;rest-theme-js&#039;, get_stylesheet_directory_uri() . &#039;\/js\/rest-theme.js&#039;, array( &#039;jquery&#039; ) );\n\n    \/\/ ...and localize The Events Calendar REST API information and nonce\n    wp_localize_script( &#039;rest-theme-js&#039;, &#039;restTheme&#039;,\n        array( &#039;root&#039; =&gt; esc_url_raw( tribe_events_rest_url() ), &#039;nonce&#039; =&gt; wp_create_nonce( &#039;wp_rest&#039; ) ) );\n}\n\n<\/pre><\/div>\n\n\n<p>We replace the theme&#8217;s <samp>index.php<\/samp> file to scaffold an empty body that we&#8217;ll fill with events fetched via The Events Calendar REST API:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ file index.php\n\n<\/pre><\/div>\n\n\n<div class=\"wrap\">\n<div id=\"rest-events\"><header>\n<h1><code>Upcoming Events<\/code><\/h1>\n<\/header><\/div>\n<\/div>\n\n\n\n<p>Finally, in the <samp>\/js\/rest-theme.js<\/samp> file, we fetch the events when the page is ready:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(\n   function( $ ) {\n       if ( undefined === restTheme ) {\n           return;\n       }\n\n       var renderEvents = function( response ) {\n           var eventsNode = null;\n\n           if ( response.events.length &amp;gt; 0 ) {\n               var eventsNode = $( '&lt;ul&gt;' ); \n                   \n                for ( var event of response.events ) { \n                    var eventNode = $( '&lt;li&gt;' ); \n                    eventNode.text( event.title ); \n                    eventNode.appendTo( eventsNode ); \n                } \n            } else { \n                var eventsNode = $( '' ); \n                eventsNode.text( 'No upcoming events found!' ); \n            } \n\n            eventsNode.appendTo( $( '#rest-events' ) ); \n        };\n         \n        var showEvents = function() {\n            $.ajax( { \n                \/\/ get The Events Caleandar REST API root URL read from the localized object \n                url: restTheme.root + 'events', \n                method: 'GET', \n                \/\/ set the `X-WP-Nonce` header to the nonce value read from the localized object \n                beforeSend: function( xhr ) { \n                    xhr.setRequestHeader( 'X-WP-Nonce', restTheme.nonce ); \n                }, \n                \/\/ set some request data \n                data: { 'page': 1, 'per_page': 3, } \n            } )\n            \/\/ when done render the events list \n            .done( renderEvents ); \n        }; \n\n        $( document ).ready( function() { showEvents(); } ); \n    } \n)( jQuery )<\/pre>\n\n\n\n<p>In this last file, we can see the cookie-based authentication in action. It consists, quite simply, of setting the <samp>X-WP-Nonce<\/samp> header on the AJAX request. WordPress will check the nonce against the content of the cookies for our user and set the user accordingly.<\/p>\n\n\n\n<p>But what happens if the wrong nonce is passed? Or if the nonce is expired? Nothing dangerous: the user will be set to <samp>0<\/samp>, the logged-out user, and capabilities will follow.<\/p>\n\n\n\n<p>To test that the authentication works, we&#8217;ve created two public events that anyone can see and a private event that only users with the <samp>edit_posts<\/samp> capability will be able to see. Visiting the site as a logged-out user (like a site visitor), we see this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2017\/09\/visitor-events-1.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>While visiting the site as an administrator, a user that can edit posts by default, we see this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2017\/09\/admin-events-665x408.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>This will be true for any type of authorization used to authenticate the users, not just for cookie-based authentication.<\/p>\n\n\n\n<p>Now, what about trying some really dangerous things, like trashing events?<\/p>\n\n\n\n<p>Let&#8217;s add a button beside each event title in the <samp>\/js\/rest-theme.js<\/samp> file that will allow users to trash the corresponding event:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(\n    (\n    function( $ ) {\n        if ( undefined === restTheme ) {\n            return;\n        }\n\n        var renderEvents = function( response ) {\n            var eventsNode = null;\n\n            if ( response.events.length &gt; 0 ) {\n                var eventsNode = $( '&lt;ul&gt;' ); \n                var eventNodeProps = { style: 'margin-bottom: 1em;' }; \n                for ( var event of response.events ) { \n                    var eventNode = $( '&lt;li&gt;', eventNodeProps ); \n                    eventNode.text( event.title ); \n                    var buttonProps = { 'data-event-id': event.id, style: 'padding: 5px; margin-left: 1em;' }; \n                    var eventNodeButton = $( '&lt;button&gt;', buttonProps ).text( 'Delete this!' ).on( 'click', deleteEvent ); \n                    eventNodeButton.appendTo( eventNode ); \n                    eventNode.appendTo( eventsNode ); \n                } \n            } else { \n                var eventsNode = $( '' ); \n                eventsNode.text( 'No upcoming events found!' ); } \n                var $container = $( '#rest-events' ); \n                $container.empty(); \n                eventsNode.appendTo( $container ); \n            }\n        };\n             \n        var showEvents = function() { \n            $.ajax( { \n                url: restTheme.root + 'events', \n                method: 'GET', \n                beforeSend: function( xhr ) {\n                    xhr.setRequestHeader( 'X-WP-Nonce', restTheme.nonce ); \n                }, \n                data: { 'page': 1, 'per_page': 3, } \n            } ).done( renderEvents ); \n        }; \n            \n        var deleteEvent = function() { \n            var $this = $( this ); \n            var eventId = $this.data( 'event-id' ); \n            if ( ! eventId ) { return; } \n            $.ajax( { \n                url: restTheme.root + 'events\/' + eventId, \n                method: 'DELETE', \n                beforeSend: function( xhr ) { \n                    xhr.setRequestHeader( 'X-WP-Nonce', restTheme.nonce ); \n                }, \n                data: {} \n            } ).done( showEvents ); \n        }\n        \n        $( document ).ready( function() { \n            showEvents(); \n        } ); \n    } \n)( jQuery ) \n<\/pre>\n\n\n\n<p>Now if we click the all-too-visible &#8220;Delete this!&#8221; button as a logged-out user, or as any user that cannot edit posts, nothing should happen.<\/p>\n\n\n\n<p>Doing the same as a user that can edit posts will, instead, delete the events:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2017\/09\/deleting-events-no.gif\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2017\/09\/deleting-event-ok.gif\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"one-click-client-generation\">One-click client generation<\/h2>\n\n\n\n<p>Remember before, when, while talking about the Swagger.io format documentation, we mentioned being able to create clients for The Events Calendar REST API in one click?<\/p>\n\n\n\n<p>Let&#8217;s see how we can do that. First of all, head to the site <samp>\/wp-json\/tribe\/events\/v1\/doc<\/samp> path on your site, and as before, copy the whole JSON format output. Head over to <a href=\"https:\/\/swagger.io\/swagger-editor\/\">the Swagger.io Editor page<\/a>:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2017\/09\/swagger-io-editor-landing-665x408.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>Click the &#8220;Online Editor&#8221; button and paste the JSON output on the editor side (on the left):<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2017\/09\/swagger-io-editor-paste-665x409.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>If you are prompted to convert the JSON input into YAML, click &#8220;OK&#8221;, count to 10, and you should see the documentation for The Events Calendar REST API appear on the right side.<\/p>\n\n\n\n<p>Now click &#8220;Generate Client&#8221; on the upper menu, and wait while someone does the work for you:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2017\/09\/swagger-io-editor-generate-665x409.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2017\/09\/swagger-io-editor-generation-gif.gif\" alt=\"\"\/><\/figure>\n\n\n\n<p>At the end, you will get an archive file containing The Events Calendar REST API client code in the selected language.<\/p>\n\n\n\n<p><strong>Note:<\/strong> If it\u2019s not working on your end after using the recommended payload and endpoint, then installing this plugin might help: https:\/\/wordpress.org\/plugins\/wp-api-swaggerui\/<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc4b This article was originally written in 2017 and some information is outdated. We are currently working to build an updated REST API guide &#8211; please see REST API Basics, REST API authentication, and REST API Troubleshooting. What is a REST API, again? If you work at all with the web, you will have probably&#8230;<\/p>\n","protected":false},"author":3,"featured_media":1955565,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_swpsp_post_exclude":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"ep_exclude_from_search":false,"footnotes":""},"categories":[84],"tags":[25,58],"stellar-product-taxonomy":[161],"class_list":["post-1896654","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-theming-overview","tag-customizations","tag-php","stellar-product-taxonomy-the-events-calendar"],"acf":[],"taxonomy_info":{"category":[{"value":84,"label":"Templating &amp; Layout"}],"post_tag":[{"value":25,"label":"Customizations"},{"value":58,"label":"PHP"}],"stellar-product-taxonomy":[{"value":161,"label":"The Events Calendar"}]},"featured_image_src_large":["https:\/\/images.theeventscalendar.com\/kb\/uploads\/2023\/02\/social-share-1024x538.png",1024,538,true],"author_info":{"display_name":"Jaime Marchwinski","author_link":"https:\/\/theeventscalendar.com\/knowledgebase\/author\/jaimetri-be\/"},"comment_info":0,"category_info":[{"term_id":84,"name":"Templating &amp; Layout","slug":"theming-overview","term_group":0,"term_taxonomy_id":84,"taxonomy":"category","description":"","parent":24,"count":59,"filter":"raw","term_order":"0","cat_ID":84,"category_count":59,"category_description":"","cat_name":"Templating &amp; Layout","category_nicename":"theming-overview","category_parent":24}],"tag_info":[{"term_id":25,"name":"Customizations","slug":"customizations","term_group":0,"term_taxonomy_id":25,"taxonomy":"post_tag","description":"","parent":0,"count":102,"filter":"raw","term_order":"0"},{"term_id":58,"name":"PHP","slug":"php","term_group":0,"term_taxonomy_id":58,"taxonomy":"post_tag","description":"","parent":20,"count":78,"filter":"raw","term_order":"0"}],"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1896654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=1896654"}],"version-history":[{"count":3,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1896654\/revisions"}],"predecessor-version":[{"id":1963084,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1896654\/revisions\/1963084"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media\/1955565"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=1896654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=1896654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=1896654"},{"taxonomy":"stellar-product-taxonomy","embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/stellar-product-taxonomy?post=1896654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}