{"id":1963091,"date":"2024-10-24T11:48:09","date_gmt":"2024-10-24T15:48:09","guid":{"rendered":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/?p=1963091"},"modified":"2024-10-24T11:53:50","modified_gmt":"2024-10-24T15:53:50","slug":"using-the-rest-api-to-manage-attendees","status":"publish","type":"post","link":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/using-the-rest-api-to-manage-attendees\/","title":{"rendered":"Using the REST API to Manage Attendees"},"content":{"rendered":"\n<p>If you haven&#8217;t already, before diving into this guide you should start with our other articles about using the REST API with The Events Calendar and Event Tickets. Get started with the <a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/event-ticket-rest-api-basics\/\" target=\"_blank\" rel=\"noreferrer noopener\">basics<\/a> and then learn how to add <a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/rest-api-authentication\/\" target=\"_blank\" rel=\"noreferrer noopener\">authentication<\/a> to your requests. Up to this point, we&#8217;ve mostly been talking about just retrieving information (<code>GET<\/code> requests), but in this guide we&#8217;re going to dive into <code>POST<\/code> requests to create new attendees and <code>PUT<\/code> requests to update existing attendees.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-create-a-new-attendee\">Create a New Attendee<\/h2>\n\n\n\n<p>First, set up an authenticated call &#8211; in this example we&#8217;ll be using an <a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/rest-api-authentication\/#h-making-a-rest-request-with-ajax\" target=\"_blank\" rel=\"noreferrer noopener\">authenticated AJAX call<\/a>. In your script file, this is what your JS will look like:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n$.ajax( {\n\t\tmethod: &#039;POST&#039;,\n\t\turl: &#039;https:\/\/your-site\/wp-json\/tribe\/tickets\/v1\/attendees&#039;,\n\t\tbeforeSend: function ( xhr ) {\n\t\t\txhr.setRequestHeader( &#039;X-WP-Nonce&#039;, ajax_variable.nonce );\n\t\t},\n\t\tdata: {\n\t\t\tticket_id: &#039;50&#039;, \n\t\t\tfull_name: &#039;Bob Saget&#039;,\n\t\t\temail: &#039;bob@mail.com&#039;,\n\t\t}\n\t} )\n} );\n<\/pre><\/div>\n\n\n<p>Let&#8217;s break this down: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>method: 'POST'<\/code> &#8211;<\/strong> This establishes that we want to add something new to the database (in this case, a new attendee).<\/li>\n\n\n\n<li><strong><code>url: \u2018https:\/\/your.site\/wp-json\/tribe\/tickets\/v1\/attendees\u2019<\/code> &#8211; <\/strong>This is the endpoint for the REST API. Make sure to replace &#8220;<code>your.site<\/code>&#8221; with your site&#8217;s actual URL. The rest of the endpoint is pointing to the Event Tickets API for attendees.<\/li>\n\n\n\n<li><strong><code>beforeSend: function (xhr)<\/code> &#8211; <\/strong>This function is used to add headers to the AJAX request. In this case, we are adding an authentication token (nonce) to the request, which is necessary to validate that the user making the request has the right permissions to create an attendee. Make sure you update the localized variable name (<code>ajax_variable.nonce<\/code>) if you used something different.<\/li>\n\n\n\n<li><strong><code>data: {\u2026}<\/code> &#8211;<\/strong> This is the body of the request, where you send the actual information needed to create the new attendee. Each key in the object corresponds to a required parameter expected by the API. There are other <a href=\"https:\/\/docs.theeventscalendar.com\/rest-endpoints\/?urls.primaryName=Tickets#\/default\/get_attendees\" target=\"_blank\" rel=\"noreferrer noopener\">attendee-specific parameters<\/a> you can optionally add, but these three are required:\n<ul class=\"wp-block-list\">\n<li><strong><code>ticket_id: \u201850\u2019<\/code> &#8211;<\/strong> The <code>ticket_id<\/code> is a string or integer that must correspond to the <code>post_id<\/code> of an existing ticket in your system. The attendee you\u2019re creating will be associated with this ticket. Without a valid <code>ticket_id<\/code>, the request will fail.<\/li>\n\n\n\n<li><strong><code>full_name: \u2018Bob Saget\u2019<\/code> &#8211;<\/strong> This is the name of the attendee you\u2019re creating. It will appear in the <a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/tickets-managing-your-orders-and-attendees\/#attendee-list\" target=\"_blank\" rel=\"noreferrer noopener\">list of attendees associated with the event<\/a>.<\/li>\n\n\n\n<li><strong><code>email: \u2018bob@mail.com\u2019<\/code> &#8211; <\/strong>This is the attendee\u2019s email address. Make sure this is a valid email, as it will be used for communication and sending the tickets, which you will have to either send manually on the attendee page or through a different customization.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-update-an-existing-attendee\">Update an Existing Attendee<\/h2>\n\n\n\n<p>The process for updating an attendee is very similar to creating a new attendee with two key differences: the request type is a <code>PUT<\/code> request (instead of a <code>POST<\/code> request), and you have to identify which attendee you want to update in the REST API. <\/p>\n\n\n\n<p>To find the <code>id<\/code> of a given attendee, you can either use a <a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/rest-api-authentication\/#h-making-a-rest-request-with-ajax\" target=\"_blank\" rel=\"noreferrer noopener\">REST API <code>GET<\/code> request<\/a>, or go to the Attendee Page and find the attendee you want to update and their <code>id<\/code> will be the number under their name:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"357\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/10\/CleanShot-2024-10-23-at-17.01.45@2x-1024x357.png\" alt=\"\" class=\"wp-image-1963267\" srcset=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/10\/CleanShot-2024-10-23-at-17.01.45@2x-1024x357.png 1024w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/10\/CleanShot-2024-10-23-at-17.01.45@2x-300x105.png 300w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/10\/CleanShot-2024-10-23-at-17.01.45@2x-768x268.png 768w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/10\/CleanShot-2024-10-23-at-17.01.45@2x-1536x535.png 1536w, https:\/\/images.theeventscalendar.com\/kb\/uploads\/2024\/10\/CleanShot-2024-10-23-at-17.01.45@2x-2048x714.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>This is what the AJAX call looks like with those adjustments:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n$.ajax( {\n\t\tmethod: &#039;PUT&#039;, \/\/ For updating existing item in database\n\t\turl: &#039;https:\/\/your-site\/wp-json\/tribe\/tickets\/v1\/attendees\/670&#039;, \/\/ Add the id of the attendee\n\t\tbeforeSend: function ( xhr ) {\n\t\t\txhr.setRequestHeader( &#039;X-WP-Nonce&#039;, ajax_variable.nonce );\n\t\t},\n\t\tdata: {\n\t\t\tticket_id: &#039;50&#039;, \n\t\t\tfull_name: &#039;Updated Name&#039;,\n\t\t\temail: &#039;updatedemail@mail.com&#039;,\n\t\t}\n\t} )\n} );\n<\/pre><\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you haven&#8217;t already, before diving into this guide you should start with our other articles about using the REST API with The Events Calendar and Event Tickets. Get started with the basics and then learn how to add authentication to your requests. Up to this point, we&#8217;ve mostly been talking about just retrieving information&#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,88],"tags":[225,25],"stellar-product-taxonomy":[156],"class_list":["post-1963091","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-customizing","category-tickets","tag-api","tag-customizations","stellar-product-taxonomy-event-tickets-plus"],"acf":[],"taxonomy_info":{"category":[{"value":24,"label":"Customizations"},{"value":88,"label":"Ticketing"}],"post_tag":[{"value":225,"label":"API"},{"value":25,"label":"Customizations"}],"stellar-product-taxonomy":[{"value":156,"label":"Event Tickets Plus"}]},"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},{"term_id":88,"name":"Ticketing","slug":"tickets","term_group":0,"term_taxonomy_id":88,"taxonomy":"category","description":"","parent":61,"count":83,"filter":"raw","term_order":"0","cat_ID":88,"category_count":83,"category_description":"","cat_name":"Ticketing","category_nicename":"tickets","category_parent":61}],"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\/1963091","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=1963091"}],"version-history":[{"count":4,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1963091\/revisions"}],"predecessor-version":[{"id":1963280,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1963091\/revisions\/1963280"}],"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=1963091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=1963091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=1963091"},{"taxonomy":"stellar-product-taxonomy","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/stellar-product-taxonomy?post=1963091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}