{"id":2890,"date":"2022-06-06T07:16:44","date_gmt":"2022-06-06T12:16:44","guid":{"rendered":"https:\/\/www.teamdesk.net\/blog\/?p=2890"},"modified":"2022-06-06T07:16:46","modified_gmt":"2022-06-06T12:16:46","slug":"google-calendar-synchronization-take-2","status":"publish","type":"post","link":"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/","title":{"rendered":"Google Calendar synchronization,\u00a0take 2"},"content":{"rendered":"\n<p>Five years ago, we <a href=\"https:\/\/www.teamdesk.net\/blog\/tips-tricks\/google-calendar-synchronization\/\" target=\"_blank\" rel=\"noreferrer noopener\">outlined<\/a> Google Calendar synchronization with TeamDesk. While we used our tools to push the data from TeamDesk to Google, on a way back we needed third-party integrator software (we used Zapier) to handle incoming changes. Now, with an addition of webhooks and iterators we can handle two-way synchronization using solely TeamDesk built-in tools. In this article we&#8217;ll show you how.<\/p>\n\n\n\n<p>First, there is the link to sample database: <\/p>\n\n\n\n<p>Example: <a href=\"https:\/\/www.teamdesk.net\/google_calendar_two_way_sync\" target=\"_blank\" rel=\"noreferrer noopener\">Google Calendar Two-Way Synchronization<\/a><\/p>\n\n\n\n<p>After creating your copy, please visit <em>Setup | Database tab | Tools | 3rd-Party Accounts | Google Account<\/em> and authorize an account to let access to your calendar. Save and here we go!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">From TeamDesk to Google Calendar<\/h2>\n\n\n\n<p>Quick recap. Google Calendar has <a href=\"https:\/\/developers.google.com\/google-apps\/calendar\/v3\/reference\/#Events\">REST API<\/a> to create and update events. Event in Google Calendar is identified by unique ID. From TeamDesk to Google Calendar the integration is fairly straightforward. When <em>Event<\/em> record in TeamDesk is added or changed, and has no stored Google Calendar Event ID, you should call Calendar&#8217;s REST API <a href=\"https:\/\/developers.google.com\/calendar\/api\/v3\/reference\/events\/insert\" target=\"_blank\" rel=\"noreferrer noopener\">insert<\/a> method and store Event ID returned back. If <em>Event<\/em> record in TeamDesk already has Google Calendar Event ID, you should rather call Calendar&#8217;s REST API <a href=\"https:\/\/developers.google.com\/calendar\/api\/v3\/reference\/events\/update\" target=\"_blank\" rel=\"noreferrer noopener\">update<\/a> method. You can easily implement this with help of two triggers and a pair of Call URL actions &#8211; as described in old article.<\/p>\n\n\n\n<p>Now to the interesting part&#8230;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">From Google Calendar to TeamDesk <\/h2>\n\n\n\n<p>While you can scan for changes in Google Calendar periodically &#8211; <em>poll<\/em>, there is also more effective way: to get the <em>notification<\/em> on change. Notification is web request Google sends to some URL at third-party system. In case of TeamDesk, webhook can serve as the receiver.<\/p>\n\n\n\n<p>To subscribe to notifications, you should register webhook&#8217;s URL with Google API. Would this be one time action, there would be numerous ways to do it, but, unfortunately the registration expires after 30 days. So, if you want to continue receiving notifications you have to renew the subscription. To do this we added <em>Google Calendar Notification Subscription<\/em> table with buttons to subscribe and unsubscribe and time-dependent trigger to handle automatic subscription renewal once current subscription expires. Once we subscribe our webhook will start receiving change notifications.<\/p>\n\n\n\n<p>Google Calendar&#8217;s notifications are short on information. Notification merely denotes the fact <em>some event<\/em> was added or changed. So, once notification arrives, we call Calendar&#8217;s <a href=\"https:\/\/developers.google.com\/calendar\/api\/v3\/reference\/events\/list\" target=\"_blank\" rel=\"noreferrer noopener\">list<\/a> method to get IDs of events changed or added since last notification. Once we have the list we can check whether ID exists in our Events table and we need to update, or ID does not exist and we have to create new Event.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">TeamDesk implementation<\/h2>\n\n\n\n<p>TeamDesk implementation takes advantage cascading trigger execution. When notification arrives into webhook, new record is created in <em>Google Calendar Notification<\/em> table. Record change trigger runs <em>Get Changed Events List<\/em> action that retrieves the list of changed IDs and stores each one as a record in <em>Google Calendar Changed Event<\/em> table. The relationship between this table and <em>Events<\/em> table allows counting events with matched <em>Google Event ID<\/em> (in fact there could be either none or only one due to unique nature of ID). On &#8230;<em>Changed Event<\/em>s there are two triggers. One works when count is zero; it creates new dummy record in <em>Events<\/em> table is created and flags it for update from Google Calendar&#8217;s Event. Another trigger works when count is non-zero; it simply flags TeamDesk <em>Event <\/em>record for update. In either case, yet another trigger, this time on <em>Events<\/em> table will call API to update the record with fresh data from Google Calendar.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With an addition of webhooks and iterators we can handle two way synchronization using solely TeamDesk built-in tools.<\/p>\n","protected":false},"author":4,"featured_media":2784,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42],"tags":[200,191,189,225],"class_list":["post-2890","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-application-library","tag-calendar","tag-calendar-synchronization","tag-google-calendar","tag-synchronization"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Google Calendar synchronization,\u00a0take 2 - TeamDesk Blog<\/title>\n<meta name=\"description\" content=\"With an addition of webhooks and iterators we can handle two-way Google Calendar synchronization using solely TeamDesk built-in tools.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Google Calendar synchronization,\u00a0take 2 - TeamDesk Blog\" \/>\n<meta property=\"og:description\" content=\"With an addition of webhooks and iterators we can handle two-way Google Calendar synchronization using solely TeamDesk built-in tools.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/\" \/>\n<meta property=\"og:site_name\" content=\"TeamDesk Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-06T12:16:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-06-06T12:16:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.teamdesk.net\/blog\/wp-content\/uploads\/2017\/05\/Sync-with-Google-Calendar-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1551\" \/>\n\t<meta property=\"og:image:height\" content=\"991\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Kirill Bondar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirill Bondar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/application-library\\\/google-calendar-synchronization-take-2\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/application-library\\\/google-calendar-synchronization-take-2\\\/\"},\"author\":{\"name\":\"Kirill Bondar\",\"@id\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/#\\\/schema\\\/person\\\/22c4c05bd657513c8b00122fa364c8d2\"},\"headline\":\"Google Calendar synchronization,\u00a0take 2\",\"datePublished\":\"2022-06-06T12:16:44+00:00\",\"dateModified\":\"2022-06-06T12:16:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/application-library\\\/google-calendar-synchronization-take-2\\\/\"},\"wordCount\":586,\"commentCount\":1,\"image\":{\"@id\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/application-library\\\/google-calendar-synchronization-take-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/05\\\/Sync-with-Google-Calendar-1.png\",\"keywords\":[\"calendar\",\"calendar synchronization\",\"google calendar\",\"synchronization\"],\"articleSection\":[\"Application Library\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/application-library\\\/google-calendar-synchronization-take-2\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/application-library\\\/google-calendar-synchronization-take-2\\\/\",\"url\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/application-library\\\/google-calendar-synchronization-take-2\\\/\",\"name\":\"Google Calendar synchronization,\u00a0take 2 - TeamDesk Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/application-library\\\/google-calendar-synchronization-take-2\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/application-library\\\/google-calendar-synchronization-take-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/05\\\/Sync-with-Google-Calendar-1.png\",\"datePublished\":\"2022-06-06T12:16:44+00:00\",\"dateModified\":\"2022-06-06T12:16:46+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/#\\\/schema\\\/person\\\/22c4c05bd657513c8b00122fa364c8d2\"},\"description\":\"With an addition of webhooks and iterators we can handle two-way Google Calendar synchronization using solely TeamDesk built-in tools.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/application-library\\\/google-calendar-synchronization-take-2\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/application-library\\\/google-calendar-synchronization-take-2\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/application-library\\\/google-calendar-synchronization-take-2\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/05\\\/Sync-with-Google-Calendar-1.png\",\"contentUrl\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/05\\\/Sync-with-Google-Calendar-1.png\",\"width\":1551,\"height\":991,\"caption\":\"Google Calendar synchronization\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/application-library\\\/google-calendar-synchronization-take-2\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Google Calendar synchronization,\u00a0take 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/\",\"name\":\"TeamDesk Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/#\\\/schema\\\/person\\\/22c4c05bd657513c8b00122fa364c8d2\",\"name\":\"Kirill Bondar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dc5bc844095b5753ccc73c589c028bf16615674f289668146bbd59205a08a52d?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dc5bc844095b5753ccc73c589c028bf16615674f289668146bbd59205a08a52d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dc5bc844095b5753ccc73c589c028bf16615674f289668146bbd59205a08a52d?s=96&d=mm&r=g\",\"caption\":\"Kirill Bondar\"},\"url\":\"https:\\\/\\\/www.teamdesk.net\\\/blog\\\/author\\\/kirill-bondar\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Google Calendar synchronization,\u00a0take 2 - TeamDesk Blog","description":"With an addition of webhooks and iterators we can handle two-way Google Calendar synchronization using solely TeamDesk built-in tools.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/","og_locale":"en_US","og_type":"article","og_title":"Google Calendar synchronization,\u00a0take 2 - TeamDesk Blog","og_description":"With an addition of webhooks and iterators we can handle two-way Google Calendar synchronization using solely TeamDesk built-in tools.","og_url":"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/","og_site_name":"TeamDesk Blog","article_published_time":"2022-06-06T12:16:44+00:00","article_modified_time":"2022-06-06T12:16:46+00:00","og_image":[{"width":1551,"height":991,"url":"https:\/\/www.teamdesk.net\/blog\/wp-content\/uploads\/2017\/05\/Sync-with-Google-Calendar-1.png","type":"image\/png"}],"author":"Kirill Bondar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirill Bondar","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/#article","isPartOf":{"@id":"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/"},"author":{"name":"Kirill Bondar","@id":"https:\/\/www.teamdesk.net\/blog\/#\/schema\/person\/22c4c05bd657513c8b00122fa364c8d2"},"headline":"Google Calendar synchronization,\u00a0take 2","datePublished":"2022-06-06T12:16:44+00:00","dateModified":"2022-06-06T12:16:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/"},"wordCount":586,"commentCount":1,"image":{"@id":"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.teamdesk.net\/blog\/wp-content\/uploads\/2017\/05\/Sync-with-Google-Calendar-1.png","keywords":["calendar","calendar synchronization","google calendar","synchronization"],"articleSection":["Application Library"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/","url":"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/","name":"Google Calendar synchronization,\u00a0take 2 - TeamDesk Blog","isPartOf":{"@id":"https:\/\/www.teamdesk.net\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/#primaryimage"},"image":{"@id":"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.teamdesk.net\/blog\/wp-content\/uploads\/2017\/05\/Sync-with-Google-Calendar-1.png","datePublished":"2022-06-06T12:16:44+00:00","dateModified":"2022-06-06T12:16:46+00:00","author":{"@id":"https:\/\/www.teamdesk.net\/blog\/#\/schema\/person\/22c4c05bd657513c8b00122fa364c8d2"},"description":"With an addition of webhooks and iterators we can handle two-way Google Calendar synchronization using solely TeamDesk built-in tools.","breadcrumb":{"@id":"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/#primaryimage","url":"https:\/\/www.teamdesk.net\/blog\/wp-content\/uploads\/2017\/05\/Sync-with-Google-Calendar-1.png","contentUrl":"https:\/\/www.teamdesk.net\/blog\/wp-content\/uploads\/2017\/05\/Sync-with-Google-Calendar-1.png","width":1551,"height":991,"caption":"Google Calendar synchronization"},{"@type":"BreadcrumbList","@id":"https:\/\/www.teamdesk.net\/blog\/application-library\/google-calendar-synchronization-take-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.teamdesk.net\/blog\/"},{"@type":"ListItem","position":2,"name":"Google Calendar synchronization,\u00a0take 2"}]},{"@type":"WebSite","@id":"https:\/\/www.teamdesk.net\/blog\/#website","url":"https:\/\/www.teamdesk.net\/blog\/","name":"TeamDesk Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.teamdesk.net\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.teamdesk.net\/blog\/#\/schema\/person\/22c4c05bd657513c8b00122fa364c8d2","name":"Kirill Bondar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/dc5bc844095b5753ccc73c589c028bf16615674f289668146bbd59205a08a52d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/dc5bc844095b5753ccc73c589c028bf16615674f289668146bbd59205a08a52d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dc5bc844095b5753ccc73c589c028bf16615674f289668146bbd59205a08a52d?s=96&d=mm&r=g","caption":"Kirill Bondar"},"url":"https:\/\/www.teamdesk.net\/blog\/author\/kirill-bondar\/"}]}},"_links":{"self":[{"href":"https:\/\/www.teamdesk.net\/blog\/wp-json\/wp\/v2\/posts\/2890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.teamdesk.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.teamdesk.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.teamdesk.net\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.teamdesk.net\/blog\/wp-json\/wp\/v2\/comments?post=2890"}],"version-history":[{"count":7,"href":"https:\/\/www.teamdesk.net\/blog\/wp-json\/wp\/v2\/posts\/2890\/revisions"}],"predecessor-version":[{"id":2900,"href":"https:\/\/www.teamdesk.net\/blog\/wp-json\/wp\/v2\/posts\/2890\/revisions\/2900"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.teamdesk.net\/blog\/wp-json\/wp\/v2\/media\/2784"}],"wp:attachment":[{"href":"https:\/\/www.teamdesk.net\/blog\/wp-json\/wp\/v2\/media?parent=2890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.teamdesk.net\/blog\/wp-json\/wp\/v2\/categories?post=2890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.teamdesk.net\/blog\/wp-json\/wp\/v2\/tags?post=2890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}