{"id":1960250,"date":"2024-05-21T12:07:38","date_gmt":"2024-05-21T16:07:38","guid":{"rendered":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/?p=1960250"},"modified":"2024-10-24T11:56:10","modified_gmt":"2024-10-24T15:56:10","slug":"event-ticket-rest-api-basics","status":"publish","type":"post","link":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/event-ticket-rest-api-basics\/","title":{"rendered":"Event\/Ticket REST API Basics"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"h-what-is-rest-api\">What is REST API<\/h2>\n\n\n\n<p>REST (<strong>RE<\/strong>presentation <strong>S<\/strong>tate <strong>T<\/strong>ransfer) API (<strong>A<\/strong>pplication <strong>P<\/strong>rogramming <strong>I<\/strong>nterface) 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 (<strong>J<\/strong>ava<strong>S<\/strong>cript <strong>O<\/strong>bject <strong>N<\/strong>otation) 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.<\/p>\n\n\n\n<p>To get you started, here are some general resources that explain how WordPress Core REST API works:<\/p>\n\n\n\n<div class=\"wp-block-group is-horizontal is-content-justification-center is-nowrap is-layout-flex wp-container-core-group-is-layout-be6bc205 wp-block-group-is-layout-flex\" style=\"border-style:none;border-width:0px;margin-top:0;margin-bottom:0;padding-top:0;padding-right:0;padding-bottom:0;padding-left:0\"><style>.wp-block-kadence-advancedbtn.kb-btns1960250_d85ec6-3f{gap:var(--global-kb-gap-xs, 0.5rem );justify-content:center;align-items:center;}.kt-btns1960250_d85ec6-3f .kt-button{font-weight:normal;font-style:normal;}.kt-btns1960250_d85ec6-3f .kt-btn-wrap-0{margin-right:5px;}.wp-block-kadence-advancedbtn.kt-btns1960250_d85ec6-3f .kt-btn-wrap-0 .kt-button{color:#555555;border-color:#555555;}.wp-block-kadence-advancedbtn.kt-btns1960250_d85ec6-3f .kt-btn-wrap-0 .kt-button:hover, .wp-block-kadence-advancedbtn.kt-btns1960250_d85ec6-3f .kt-btn-wrap-0 .kt-button:focus{color:#ffffff;border-color:#444444;}.wp-block-kadence-advancedbtn.kt-btns1960250_d85ec6-3f .kt-btn-wrap-0 .kt-button::before{display:none;}.wp-block-kadence-advancedbtn.kt-btns1960250_d85ec6-3f .kt-btn-wrap-0 .kt-button:hover, .wp-block-kadence-advancedbtn.kt-btns1960250_d85ec6-3f .kt-btn-wrap-0 .kt-button:focus{background:#444444;}<\/style>\n<div class=\"wp-block-kadence-advancedbtn kb-buttons-wrap kb-btns1960250_d85ec6-3f\"><style>ul.menu .wp-block-kadence-advancedbtn .kb-btn1960250_7b1859-6c.kb-button{width:initial;}<\/style><a class=\"kb-button kt-button button kb-btn1960250_7b1859-6c kt-btn-size-standard kt-btn-width-type-auto kb-btn-global-inherit kt-btn-has-text-true kt-btn-has-svg-false  wp-block-button__link wp-block-kadence-singlebtn\" href=\"https:\/\/developer.wordpress.org\/rest-api\/\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"kt-btn-inner-text\">REST API Handbook<\/span><\/a>\n\n<style>ul.menu .wp-block-kadence-advancedbtn .kb-btn1960250_4b2a13-89.kb-button{width:initial;}<\/style><a class=\"kb-button kt-button button kb-btn1960250_4b2a13-89 kt-btn-size-standard kt-btn-width-type-auto kb-btn-global-inherit kt-btn-has-text-true kt-btn-has-svg-false  wp-block-button__link wp-block-kadence-singlebtn\" href=\"https:\/\/developer.wordpress.com\/docs\/api\/\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"kt-btn-inner-text\">Endpoints<\/span><\/a>\n\n<style>ul.menu .wp-block-kadence-advancedbtn .kb-btn1960250_ec38b7-fe.kb-button{width:initial;}<\/style><a class=\"kb-button kt-button button kb-btn1960250_ec38b7-fe kt-btn-size-standard kt-btn-width-type-auto kb-btn-global-inherit kt-btn-has-text-true kt-btn-has-svg-false  wp-block-button__link wp-block-kadence-singlebtn\" href=\"https:\/\/kinsta.com\/blog\/wordpress-rest-api\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><span class=\"kt-btn-inner-text\">Beginner Guide<\/span><\/a><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-event-ticket-rest-api-endpoints\">Event\/Ticket REST API Endpoints<\/h2>\n\n\n\n<p>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:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">\n&#x5B;your-site-URL]\/wp-json\/tribe\/events\/v1\/{endpoint}\n<\/pre><\/div>\n\n\n<p>Let&#8217;s break this down further.<\/p>\n\n\n\n<p><code>[your-site-URL]\/<\/code> &#8211; this is the part of the request asking where we want to get information from (AKA which server).<\/p>\n\n\n\n<p><code>\/wp-json\/tribe\/events\/v1<\/code> &#8211; the <code>\/wp-json<\/code> is part of <a href=\"https:\/\/developer.wordpress.org\/rest-api\/key-concepts\/#routes-endpoints\">WP Core REST API endpoints<\/a> and the other parts specify which plugin we want information from. To get all ticket routes, you would simply switch out <code>\/events<\/code> for <code>\/tickets<\/code>.<\/p>\n\n\n\n<p><code>\/{endpoint}<\/code> &#8211; this optional part can add even more specificity for what information the API call returns. Check out our more in-depth documentation on <a href=\"https:\/\/docs.theeventscalendar.com\/rest-endpoints\/\">available REST API endpoints<\/a> for events and tickets. You can also use the <code>\/doc<\/code> endpoint to see all available endpoints. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-get-request\">Example GET Request<\/h2>\n\n\n\n<p>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):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">\nGET https:\/\/demo.theeventscalendar.com\/wp-json\/tribe\/events\/v1\/events\n<\/pre><\/div>\n\n\n<p><br>And that would return a JSON that looks something like this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n{\n  &quot;events&quot;: &#x5B;\n    {\n      &quot;id&quot;: 1762,\n      &quot;global_id&quot;: &quot;demo.theeventscalendar.com?id=1762&quot;,\n      &quot;global_id_lineage&quot;: &#x5B;\n        &quot;demo.theeventscalendar.com?id=1762&quot;\n      ],\n      &quot;author&quot;: &quot;2&quot;,\n      &quot;status&quot;: &quot;publish&quot;,\n      &quot;date&quot;: &quot;2022-12-01 12:36:40&quot;,\n      &quot;date_utc&quot;: &quot;2022-12-01 17:36:40&quot;,\n      &quot;modified&quot;: &quot;2023-12-19 14:00:59&quot;,\n      &quot;modified_utc&quot;: &quot;2023-12-19 19:00:59&quot;,\n      &quot;url&quot;: &quot;https:\/\/demo.theeventscalendar.com\/event\/hosted-dinner-with-chef-monica-geller\/&quot;,\n      &quot;rest_url&quot;: &quot;https:\/\/demo.theeventscalendar.com\/wp-json\/tribe\/events\/v1\/events\/1762&quot;,\n      &quot;title&quot;: &quot;Hosted Dinner with Chef Monica Geller&quot;,\n      &quot;description&quot;: &quot;&lt;p&gt;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.&lt;\/p&gt;&quot;,\n      &quot;excerpt&quot;: &quot;&quot;,\n      &quot;slug&quot;: &quot;hosted-dinner-with-chef-monica-geller&quot;,\n      \/\/ Cut short for brevity\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-query-parameter-example\">Query Parameter Example<\/h2>\n\n\n\n<p>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 <a href=\"https:\/\/docs.theeventscalendar.com\/rest-endpoints\">endpoints<\/a> and <a href=\"https:\/\/developer.wordpress.org\/rest-api\/requests\/#parameters\">query parameters<\/a> to explore so you can whittle down the response to exactly what you&#8217;re looking for!<\/p>\n\n\n\n<p>For example, this is what a <code>GET<\/code> request looks like to only return tickets that have Individual Attendee Collection enabled:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">\nGET https:\/\/demo.theeventscalendar.com\/wp-json\/tribe\/tickets\/v1\/tickets?attendee_information_available=true\n<\/pre><\/div>\n\n\n<p>This will only return 2 out of the 5 ticket objects on our demo site &#8211; remove the query parameter (<code>?attendee_information_available=true<\/code>) to see all 5 ticket objects.<\/p>\n\n\n\n\n<style>.kadence-column1960250_e81671-f3 > .kt-inside-inner-col,.kadence-column1960250_e81671-f3 > .kt-inside-inner-col:before{border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;}.kadence-column1960250_e81671-f3 > .kt-inside-inner-col{column-gap:var(--global-kb-gap-sm, 1rem);}.kadence-column1960250_e81671-f3 > .kt-inside-inner-col{flex-direction:column;}.kadence-column1960250_e81671-f3 > .kt-inside-inner-col > .aligncenter{width:100%;}.kadence-column1960250_e81671-f3 > .kt-inside-inner-col:before{opacity:0.3;}.kadence-column1960250_e81671-f3{position:relative;}@media all and (max-width: 1024px){.kadence-column1960250_e81671-f3 > .kt-inside-inner-col{flex-direction:column;justify-content:center;}}@media all and (max-width: 767px){.kadence-column1960250_e81671-f3 > .kt-inside-inner-col{flex-direction:column;justify-content:center;}}<\/style>\n<div class=\"wp-block-kadence-column kadence-column1960250_e81671-f3\"><div class=\"kt-inside-inner-col\">\n<p class=\"has-theme-palette-8-background-color has-background\">\ud83d\udc4b You may notice in the JSONs returned for tickets that the <code>attendees<\/code> 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 &#8211; you can learn how to do this in this article about <a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/rest-api-authentication\/\" target=\"_blank\" rel=\"noreferrer noopener\">REST API authentication<\/a>.<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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,&#8230;<\/p>\n","protected":false},"author":44,"featured_media":1955565,"comment_status":"open","ping_status":"open","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":[24],"tags":[225,25],"stellar-product-taxonomy":[155,161],"class_list":["post-1960250","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-customizing","tag-api","tag-customizations","stellar-product-taxonomy-event-tickets","stellar-product-taxonomy-the-events-calendar"],"acf":[],"taxonomy_info":{"category":[{"value":24,"label":"Customizations"}],"post_tag":[{"value":225,"label":"API"},{"value":25,"label":"Customizations"}],"stellar-product-taxonomy":[{"value":155,"label":"Event Tickets"},{"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":"Sam Dokus","author_link":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/author\/sam-dokus\/"},"comment_info":0,"category_info":[{"term_id":24,"name":"Customizations","slug":"customizing","term_group":0,"term_taxonomy_id":24,"taxonomy":"category","description":"","parent":0,"count":110,"filter":"raw","term_order":"0","cat_ID":24,"category_count":110,"category_description":"","cat_name":"Customizations","category_nicename":"customizing","category_parent":0}],"tag_info":[{"term_id":225,"name":"API","slug":"api","term_group":0,"term_taxonomy_id":225,"taxonomy":"post_tag","description":"","parent":0,"count":5,"filter":"raw","term_order":"0"},{"term_id":25,"name":"Customizations","slug":"customizations","term_group":0,"term_taxonomy_id":25,"taxonomy":"post_tag","description":"","parent":0,"count":177,"filter":"raw","term_order":"0"}],"_links":{"self":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1960250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=1960250"}],"version-history":[{"count":8,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1960250\/revisions"}],"predecessor-version":[{"id":1961362,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1960250\/revisions\/1961362"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media\/1955565"}],"wp:attachment":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=1960250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=1960250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=1960250"},{"taxonomy":"stellar-product-taxonomy","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/stellar-product-taxonomy?post=1960250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}