Skip to content

Instantly share code, notes, and snippets.

@ArthurSteijn
Created November 1, 2021 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ArthurSteijn/dcaf5c23b905a8b9cfd00dab82c3d346 to your computer and use it in GitHub Desktop.
Save ArthurSteijn/dcaf5c23b905a8b9cfd00dab82c3d346 to your computer and use it in GitHub Desktop.
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "UpdatedEventExists",
"type": "boolean",
"value": "@false"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Switch": {
"cases": {
"Case": {
"actions": {
"Create_event_(V4)": {
"inputs": {
"body": {
"body": "<p>@{triggerBody()?['id']}</p>",
"end": "@triggerBody()?['end']",
"isReminderOn": false,
"showAs": "busy",
"start": "@triggerBody()?['start']",
"subject": "Vf:@{triggerBody()?['subject']}",
"timeZone": "@triggerBody()?['timeZone']"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365_1']['connectionId']"
}
},
"method": "post",
"path": "/datasets/calendars/v4/tables/@{encodeURIComponent(encodeURIComponent('<CalendarID>'))}/items"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"case": "added"
},
"Case_2": {
"actions": {
"Condition_2": {
"actions": {
"Create_event_(V4)_3": {
"inputs": {
"body": {
"body": "<p>@{triggerBody()?['id']}</p>",
"end": "@triggerBody()?['end']",
"isReminderOn": false,
"showAs": "busy",
"start": "@triggerBody()?['start']",
"subject": "Vf:@{triggerBody()?['subject']}",
"timeZone": "@triggerBody()?['timeZone']"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365_1']['connectionId']"
}
},
"method": "post",
"path": "/datasets/calendars/v4/tables/@{encodeURIComponent(encodeURIComponent('<CalendarID>'))}/items"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"expression": {
"and": [
{
"equals": [
"@variables('UpdatedEventExists')",
"@false"
]
}
]
},
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "If"
},
"For_each": {
"actions": {
"Condition": {
"actions": {
"Create_event_(V4)_2": {
"inputs": {
"body": {
"body": "<p>@{triggerBody()?['id']}<br>\n</p>",
"end": "@triggerBody()?['end']",
"isReminderOn": false,
"showAs": "busy",
"start": "@triggerBody()?['start']",
"subject": "Vf:@{triggerBody()?['subject']}",
"timeZone": "@triggerBody()?['timeZone']"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365_1']['connectionId']"
}
},
"method": "post",
"path": "/datasets/calendars/v4/tables/@{encodeURIComponent(encodeURIComponent('<CalendarID>'))}/items"
},
"runAfter": {
"Delete_event_(V2)": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"Delete_event_(V2)": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['office365_1']['connectionId']"
}
},
"method": "delete",
"path": "/codeless/v1.0/me/calendars/@{encodeURIComponent(encodeURIComponent('<CalendarID>'))}/events/@{encodeURIComponent(encodeURIComponent(items('For_each')?['id']))}"
},
"runAfter": {},
"type": "ApiConnection"
},
"Set_variable": {
"inputs": {
"name": "UpdatedEventExists",
"value": "@true"
},
"runAfter": {
"Create_event_(V4)_2": [
"Succeeded"
]
},
"type": "SetVariable"
}
},
"expression": {
"and": [
{
"contains": [
"@items('For_each')?['body']",
"@triggerBody()?['id']"
]
}
]
},
"runAfter": {},
"type": "If"
}
},
"foreach": "@body('Get_events_(V4)')?['value']",
"runAfter": {
"Get_events_(V4)": [
"Succeeded"
]
},
"runtimeConfiguration": {
"concurrency": {
"repetitions": 1
}
},
"type": "Foreach"
},
"Get_events_(V4)": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['office365_1']['connectionId']"
}
},
"method": "get",
"path": "/datasets/calendars/v4/tables/@{encodeURIComponent(encodeURIComponent('<CalendarID>'))}/items",
"queries": {
"$filter": "contains(Subject, '@{triggerBody()?['subject']}')"
}
},
"runAfter": {},
"type": "ApiConnection"
}
},
"case": "updated"
},
"Case_3": {
"actions": {
"For_each_2": {
"actions": {
"Condition_3": {
"actions": {
"Delete_event_(V2)_2": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['office365_1']['connectionId']"
}
},
"method": "delete",
"path": "/codeless/v1.0/me/calendars/@{encodeURIComponent(encodeURIComponent('<CalendarID>'))}/events/@{encodeURIComponent(encodeURIComponent(items('For_each_2')?['id']))}"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"expression": {
"and": [
{
"contains": [
"@items('For_each_2')?['body']",
"@triggerBody()?['id']"
]
}
]
},
"runAfter": {},
"type": "If"
}
},
"foreach": "@body('Get_events_(V4)_2')?['value']",
"runAfter": {
"Get_events_(V4)_2": [
"Succeeded"
]
},
"type": "Foreach"
},
"Get_events_(V4)_2": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['office365_1']['connectionId']"
}
},
"method": "get",
"path": "/datasets/calendars/v4/tables/@{encodeURIComponent(encodeURIComponent('<CalendarID>'))}/items",
"queries": {
"$filter": "contains(Subject, 'Vf:')"
}
},
"runAfter": {},
"type": "ApiConnection"
}
},
"case": "deleted"
}
},
"default": {
"actions": {}
},
"expression": "@triggerBody()?['ActionType']",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Switch"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"When_an_event_is_added,_updated_or_deleted_(V3)": {
"conditions": [],
"inputs": {
"fetch": {
"method": "get",
"pathTemplate": {
"parameters": {
"table": "@{encodeURIComponent(encodeURIComponent('<CalendarID>'))}"
},
"template": "/datasets/calendars/v3/tables/{table}/onchangeditems"
},
"queries": {
"incomingDays": 30,
"pastDays": 1
}
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"subscribe": {
"body": {
"NotificationUrl": "@{listCallbackUrl()}"
},
"method": "post",
"pathTemplate": {
"parameters": {
"table": "@{encodeURIComponent(encodeURIComponent('<CalendarID>'))}"
},
"template": "/{table}/GraphEventSubscriptionPoke/$subscriptions"
},
"queries": {
"incomingDays": 30,
"pastDays": 1
}
}
},
"runtimeConfiguration": {
"concurrency": {
"runs": 50
}
},
"splitOn": "@triggerBody()?['value']",
"type": "ApiConnectionNotification"
}
}
},
"parameters": {
"$connections": {
"value": {
"office365": {
"connectionId": "/subscriptions/<subscriptionID>/resourceGroups/<resourceGroupName>/providers/Microsoft.Web/connections/office365",
"connectionName": "office365",
"id": "/subscriptions/<subscriptionID>/providers/Microsoft.Web/locations/westeurope/managedApis/office365"
},
"office365_1": {
"connectionId": "/subscriptions/<subscriptionID>/resourceGroups/<resourceGroupName>/providers/Microsoft.Web/connections/office365-1",
"connectionName": "office365-1",
"id": "/subscriptions/<subscriptionID>/providers/Microsoft.Web/locations/westeurope/managedApis/office365"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment