Syncing Office 365 Calendar to Google calendar via Ofifce 365 Power Automate

0

Some time ago I've created a flow in the Office 365 Power Automate (back then it was called Flow) application which would generate a Google Calendar entry every time an Office 365 Calendar entry was generated. The flow was created out of the template: 'Sync events from Office 365 Calendar to Google Calendar.'

This worked fine but it no longer works now. The last step of the flow where the entry has to be entered in Google Calendar via Google API is failing due to a following error:

InvalidTemplate. Unable to process template language expressions in action 'Create_an_event' inputs at line '1' and column '2859': 'The template language function 'substring' parameter is out of range: 'start index' must be non-negative integer and should be less than the length of the string. Please see https://aka.ms/logicexpressions#substring for usage details.'.

Here is the failing event:

"Create_an_event":{
   "runAfter":{
      "Html_to_text":[
         "Succeeded"
      ]
   },
   "metadata":{
      "flowSystemMetadata":{
         "swaggerOperationId":"CreateEvent"
      }
   },
   "type":"ApiConnection",
   "inputs":{
      "host":{
         "connection":{
            "name":"@parameters('$connections')['googlecalendar']['connectionId']"
         }
      },
      "method":"post",
      "path":"/calendars/@{encodeURIComponent(variables('CalendarId'))}/events",
      "body":{
         "summary":"@items('Create_events_in_Google_Calendar_')?['Subject']",
         "start":"@items('Create_events_in_Google_Calendar_')?['Start']",
         "end":"@items('Create_events_in_Google_Calendar_')?['End']",
         "description":"@{substring(coalesce(body('Html_to_text'),''), 0, min(length(coalesce(body('Html_to_text'),'')),7500))}\n-------\nCopied from your Office 365 calendar (@{items('Create_events_in_Google_Calendar_')?['Id']})\nMaster Event (@{items('Create_events_in_Google_Calendar_')?['SeriesMasterId']})\nCheck out how template works and limitations: https://aka.ms/flowcalendar",
         "location":"@items('Create_events_in_Google_Calendar_')?['Location']"
      },
      "authentication":"@parameters('$authentication')",
      "retryPolicy":{
         "type":"exponential",
         "count":6,
         "interval":"PT10S",
         "minimumInterval":"PT10S",
         "maximumInterval":"PT20M"
      }
   }

Here is exported flow (I've left it minified to conserve space) which should be importable:

{"$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#","contentVersion":"1.0.0.0","parameters":{"logicAppName":{"type":"String","metadata":{"description":"Name of the logic app."}},"logicAppLocation":{"defaultValue":"[resourceGroup().location]","allowedValues":["eastasia","southeastasia","centralus","eastus","eastus2","westus","northcentralus","southcentralus","northeurope","westeurope","japanwest","japaneast","brazilsouth","australiaeast","australiasoutheast","southindia","centralindia","westindia","canadacentral","canadaeast","westcentralus","westus2","[resourceGroup().location]"],"type":"String","metadata":{"description":"Location of the logic app."}},"googlecalendar_Connection_Name":{"defaultValue":"googlecalendar","type":"String","metadata":{"description":"Name of the connection."}},"conversionservice_Connection_Name":{"defaultValue":"conversionservice","type":"String","metadata":{"description":"Name of the connection."}},"office365_Connection_Name":{"defaultValue":"office365","type":"String","metadata":{"description":"Name of the connection."}}},"resources":[{"type":"Microsoft.Logic/workflows","name":"[parameters('logicAppName')]","apiVersion":"2016-06-01","location":"[parameters('logicAppLocation')]","properties":{"state":"Disabled","definition":{"$schema":"https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#","contentVersion":"1.0.0.0","parameters":{"$connections":{"defaultValue":{},"type":"Object"},"$authentication":{"defaultValue":{},"type":"SecureObject"}},"triggers":{"When_an_event_is_changed":{"recurrence":{"interval":5,"frequency":"Minute"},"metadata":{"flowSystemMetadata":{"swaggerOperationId":"CalendarGetOnChangedItems"}},"type":"ApiConnection","inputs":{"host":{"connection":{"name":"@parameters('$connections')['office365']['connectionId']"}},"method":"get","path":"/datasets/calendars/tables/@{encodeURIComponent(encodeURIComponent('AQMkADU1ADQ1NjJiZC1hYjMxLTQwYWQtYjRjMC1kYzUzNGRjMTNkYTYARgAAA97An0gINiVBosKRdXg0O6kHAAJ2OlLJYS1AqYTVRDyX0K8AAAIBBgAAAAJ2OlLJYS1AqYTVRDyX0K8AAAIkAwAAAA=='))}/onchangeditems","queries":{"incomingDays":180,"pastDays":90},"authentication":"@parameters('$authentication')"},"runtimeConfiguration":{"concurrency":{"runs":1}}}},"actions":{"Initialize_CalendarId_variable":{"runAfter":{"Select_Calendar":["Succeeded"]},"type":"InitializeVariable","inputs":{"variables":[{"name":"CalendarId","type":"String","value":"@{decodeUriComponent(split(actions('Select_Calendar')['inputs']['path'],'/')[2])}"}]}},"Select_Calendar":{"runAfter":{},"metadata":{"flowSystemMetadata":{"swaggerOperationId":"ListEvents"}},"type":"ApiConnection","inputs":{"host":{"connection":{"name":"@parameters('$connections')['googlecalendar']['connectionId']"}},"method":"get","path":"/calendars/@{encodeURIComponent('dcarapic@gmail.com')}/events","queries":{"timeMin":"@{utcNow()}","timeMax":"@{addSeconds(utcNow(),1)}"},"authentication":"@parameters('$authentication')"}},"Create_events_in_Google_Calendar_":{"foreach":"@triggerBody()?['value']","actions":{"Check_Action_Type_for_insert_,update_and_deleted":{"actions":{"Check_if_it_is_a_google_calendar":{"actions":{"Html_to_text":{"runAfter":{},"metadata":{"flowSystemMetadata":{"swaggerOperationId":"HtmlToText"}},"type":"ApiConnection","inputs":{"host":{"connection":{"name":"@parameters('$connections')['conversionservice']['connectionId']"}},"method":"post","path":"/html2text","body":"@items('Create_events_in_Google_Calendar_')?['Body']","authentication":"@parameters('$authentication')"}},"Create_an_event":{"runAfter":{"Html_to_text":["Succeeded"]},"metadata":{"flowSystemMetadata":{"swaggerOperationId":"CreateEvent"}},"type":"ApiConnection","inputs":{"host":{"connection":{"name":"@parameters('$connections')['googlecalendar']['connectionId']"}},"method":"post","path":"/calendars/@{encodeURIComponent(variables('CalendarId'))}/events","body":{"summary":"@items('Create_events_in_Google_Calendar_')?['Subject']","start":"@items('Create_events_in_Google_Calendar_')?['Start']","end":"@items('Create_events_in_Google_Calendar_')?['End']","description":"@{substring(coalesce(body('Html_to_text'),''), 0, min(length(coalesce(body('Html_to_text'),'')),7500))}\n-------\nCopied from your Office 365 calendar (@{items('Create_events_in_Google_Calendar_')?['Id']})\nMaster Event (@{items('Create_events_in_Google_Calendar_')?['SeriesMasterId']})\nCheck out how template works and limitations: https://aka.ms/flowcalendar","location":"@items('Create_events_in_Google_Calendar_')?['Location']"},"authentication":"@parameters('$authentication')","retryPolicy":{"type":"exponential","count":6,"interval":"PT10S","minimumInterval":"PT10S","maximumInterval":"PT20M"}}}},"runAfter":{},"expression":"@not(contains(items('Create_events_in_Google_Calendar_')?['Body'], 'on your Google Calendar'))","type":"If","description":"This check is to avoid bidirectional sync"}},"runAfter":{},"else":{"actions":{"List_the_deleted_events_on_a_calendar_1":{"runAfter":{},"metadata":{"flowSystemMetadata":{"swaggerOperationId":"ListEvents"}},"type":"ApiConnection","inputs":{"host":{"connection":{"name":"@parameters('$connections')['googlecalendar']['connectionId']"}},"method":"get","path":"/calendars/@{encodeURIComponent(variables('CalendarId'))}/events","queries":{"timeMin":"@{addDays(utcNow(),-90,'yyyy-MM-ddThh:mm:ss.fffZ')}","timeMax":"@{addDays(utcNow(),180,'yyyy-MM-ddThh:mm:ss.fffZ')}","q":"@items('Create_events_in_Google_Calendar_')?['Id']"},"authentication":"@parameters('$authentication')"}},"Iterate_through_deleted_events_1":{"foreach":"@body('List_the_deleted_events_on_a_calendar_1')?['items']","actions":{"Delete_an_event_4":{"runAfter":{},"metadata":{"flowSystemMetadata":{"swaggerOperationId":"DeleteEvent"}},"type":"ApiConnection","inputs":{"host":{"connection":{"name":"@parameters('$connections')['googlecalendar']['connectionId']"}},"method":"delete","path":"/calendars/@{encodeURIComponent(variables('CalendarId'))}/events/@{encodeURIComponent(items('Iterate_through_deleted_events_1')?['id'])}","authentication":"@parameters('$authentication')"}}},"runAfter":{"List_the_deleted_events_on_a_calendar_1":["Succeeded"]},"type":"Foreach"}}},"expression":"@not(equals(items('Create_events_in_Google_Calendar_')?['ActionType'], 'deleted'))","type":"If"}},"runAfter":{"Iterate_through_recurring_events":["Succeeded"]},"type":"Foreach","description":"Iterate through the collection of events from  Office 365","runtimeConfiguration":{"concurrency":{"repetitions":25}}},"Cleanup_Google_Calendars_(Delete_existing)":{"actions":{"Apply_to_each":{"foreach":"@triggerBody()?['value']","actions":{"Check_Action_Type":{"actions":{"Check_Event_Type":{"actions":{"List_the_non_recurring_events_on_a_calendar":{"runAfter":{},"metadata":{"flowSystemMetadata":{"swaggerOperationId":"ListEvents"}},"type":"ApiConnection","inputs":{"host":{"connection":{"name":"@parameters('$connections')['googlecalendar']['connectionId']"}},"method":"get","path":"/calendars/@{encodeURIComponent(variables('CalendarId'))}/events","queries":{"timeMin":"@{addDays(utcNow(),-90,'yyyy-MM-ddThh:mm:ss.fffZ')}","timeMax":"@{addDays(utcNow(),180,'yyyy-MM-ddThh:mm:ss.fffZ')}","q":"@items('Apply_to_each')?['Id']"},"authentication":"@parameters('$authentication')"}},"Iterate_through_the_non_recurring_events":{"foreach":"@body('List_the_non_recurring_events_on_a_calendar')?['items']","actions":{"Delete_an_event":{"runAfter":{},"metadata":{"flowSystemMetadata":{"swaggerOperationId":"DeleteEvent"}},"type":"ApiConnection","inputs":{"host":{"connection":{"name":"@parameters('$connections')['googlecalendar']['connectionId']"}},"method":"delete","path":"/calendars/@{encodeURIComponent(variables('CalendarId'))}/events/@{encodeURIComponent(items('Iterate_through_the_non_recurring_events')?['id'])}","authentication":"@parameters('$authentication')"}}},"runAfter":{"List_the_non_recurring_events_on_a_calendar":["Succeeded"]},"type":"Foreach"}},"runAfter":{},"expression":"@empty(items('Apply_to_each')?['SeriesMasterId'])","type":"If","description":"Check whether it is recurring or non recurring event"}},"runAfter":{},"expression":"@not(equals(items('Apply_to_each')?['ActionType'], 'deleted'))","type":"If"}},"runAfter":{},"type":"Foreach"}},"runAfter":{"Get_distinct_master_event_Ids":["Succeeded"]},"type":"Scope","description":"Cleanup when the action type is added or updated. When the action type is deleted the deletion will be performed in the later stage."},"Iterate_through_recurring_events":{"foreach":"@outputs('Distinct_master_Ids')","actions":{"Condition":{"actions":{"List_the_events_on_a_calendar":{"runAfter":{},"metadata":{"flowSystemMetadata":{"swaggerOperationId":"ListEvents"}},"type":"ApiConnection","inputs":{"host":{"connection":{"name":"@parameters('$connections')['googlecalendar']['connectionId']"}},"method":"get","path":"/calendars/@{encodeURIComponent(variables('CalendarId'))}/events","queries":{"timeMin":"@{addDays(utcNow(),-90,'yyyy-MM-ddThh:mm:ss.fffZ')}","timeMax":"@{addDays(utcNow(),180,'yyyy-MM-ddThh:mm:ss.fffZ')}","q":"@{items('Iterate_through_recurring_events')}"},"authentication":"@parameters('$authentication')"}},"Deleting_recurring_instances":{"foreach":"@body('List_the_events_on_a_calendar')?['items']","actions":{"Delete_Google_Calendar_event":{"runAfter":{},"metadata":{"flowSystemMetadata":{"swaggerOperationId":"DeleteEvent"}},"type":"ApiConnection","inputs":{"host":{"connection":{"name":"@parameters('$connections')['googlecalendar']['connectionId']"}},"method":"delete","path":"/calendars/@{encodeURIComponent(variables('CalendarId'))}/events/@{encodeURIComponent(items('Deleting_recurring_instances')?['id'])}","authentication":"@parameters('$authentication')","retryPolicy":{"type":"exponential","count":6,"interval":"PT10S","minimumInterval":"PT10S","maximumInterval":"PT20M"}}}},"runAfter":{"List_the_events_on_a_calendar":["Succeeded"]},"type":"Foreach","runtimeConfiguration":{"concurrency":{"repetitions":25}}}},"runAfter":{},"expression":"@not(empty(items('Iterate_through_recurring_events')))","type":"If"}},"runAfter":{"Cleanup_Google_Calendars_(Delete_existing)":["Succeeded"]},"type":"Foreach"},"Get_distinct_master_event_Ids":{"actions":{"Select":{"runAfter":{},"type":"Select","inputs":{"from":"@triggerBody()?['value']","select":"@if(equals(item()?['ActionType'],'deleted'),'',coalesce(item()?['SeriesMasterId'],''))"}},"Distinct_master_Ids":{"runAfter":{"Select":["Succeeded"]},"type":"Compose","inputs":"@union(body('Select'),body('Select'))"}},"runAfter":{"Initialize_CalendarId_variable":["Succeeded"]},"type":"Scope"}},"outputs":{},"description":"Sync changes including adding, updating and deleting from Office 365 Calendar to Google Calendar."},"parameters":{"$connections":{"value":{"googlecalendar":{"id":"[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'googlecalendar')]","connectionId":"[resourceId('Microsoft.Web/connections', parameters('googlecalendar_Connection_Name'))]","connectionName":"[parameters('googlecalendar_Connection_Name')]"},"conversionservice":{"id":"[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'conversionservice')]","connectionId":"[resourceId('Microsoft.Web/connections', parameters('conversionservice_Connection_Name'))]","connectionName":"[parameters('conversionservice_Connection_Name')]"},"office365":{"id":"[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'office365')]","connectionId":"[resourceId('Microsoft.Web/connections', parameters('office365_Connection_Name'))]","connectionName":"[parameters('office365_Connection_Name')]"}}}},"runtimeConfiguration":{"lifetime":{"unit":"Day","count":30},"collections":{"maximumItemCount":5000},"performanceProfile":{"throttles":{"mode":"Low"}},"retryPolicy":{"type":"Exponential","interval":"PT7S","count":2,"minimumInterval":"PT5S","maximumInterval":"PT1H"}}},"dependsOn":["[resourceId('Microsoft.Web/connections', parameters('googlecalendar_Connection_Name'))]","[resourceId('Microsoft.Web/connections', parameters('conversionservice_Connection_Name'))]","[resourceId('Microsoft.Web/connections', parameters('office365_Connection_Name'))]"]},{"type":"Microsoft.Web/connections","name":"[parameters('googlecalendar_Connection_Name')]","apiVersion":"2016-06-01","location":"[parameters('logicAppLocation')]","properties":{"api":{"id":"[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'googlecalendar')]"},"displayName":"[parameters('googlecalendar_Connection_Name')]"}},{"type":"Microsoft.Web/connections","name":"[parameters('conversionservice_Connection_Name')]","apiVersion":"2016-06-01","location":"[parameters('logicAppLocation')]","properties":{"api":{"id":"[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'conversionservice')]"},"displayName":"[parameters('conversionservice_Connection_Name')]"}},{"type":"Microsoft.Web/connections","name":"[parameters('office365_Connection_Name')]","apiVersion":"2016-06-01","location":"[parameters('logicAppLocation')]","properties":{"api":{"id":"[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'office365')]"},"displayName":"[parameters('office365_Connection_Name')]"}}]}

Does anyone know how to fix this issue?

Dalibor Čarapić

Posted 2019-11-26T08:21:02.410

Reputation: 143

No answers