{
  "name": "Meetings to Google Calendar Sync",
  "nodes": [
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "everyXMinutes",
              "value": 3
            }
          ]
        }
      },
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "authentication": "genericCredentialType",
        "resource": "database",
        "operation": "query",
        "databaseId": "24ddcbfd883580feab1dfa7270343d5b",
        "options": {}
      },
      "name": "Notion Query",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        460,
        300
      ],
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "execute",
        "value": "={{$node['Notion Query'].json['results']}}"
      },
      "name": "Loop Over Notion Pages",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "event",
        "calendar": "85e8d827fde536807e1317e061a1fa3310c72c6050c933ec0e5d6e4df7bb96ee@group.calendar.google.com",
        "operation": "{{$node['Loop Over Notion Pages'].json['properties']['Google Event ID']['rich_text'] ? 'update' : 'create'}}",
        "event": {
          "summary": "{{$node['Loop Over Notion Pages'].json['properties']['Ac Name']['title'][0]['plain_text']}}",
          "start": {
            "dateTime": "{{$node['Loop Over Notion Pages'].json['properties']['Date']['date']['start'].includes('12:00:00') ? null : $node['Loop Over Notion Pages'].json['properties']['Date']['date']['start'] + 'Z'}}",
            "date": "{{$node['Loop Over Notion Pages'].json['properties']['Date']['date']['start'].includes('12:00:00') ? $node['Loop Over Notion Pages'].json['properties']['Date']['date']['start'].split('T')[0] : null}}"
          },
          "end": {
            "dateTime": "{{$node['Loop Over Notion Pages'].json['properties']['Date']['date']['end'] && !$node['Loop Over Notion Pages'].json['properties']['Date']['date']['end'].includes('12:00:00') ? $node['Loop Over Notion Pages'].json['properties']['Date']['date']['end'] + 'Z' : null}}",
            "date": "{{$node['Loop Over Notion Pages'].json['properties']['Date']['date']['end'] && $node['Loop Over Notion Pages'].json['properties']['Date']['date']['end'].includes('12:00:00') ? $node['Loop Over Notion Pages'].json['properties']['Date']['date']['end'].split('T')[0] : ($node['Loop Over Notion Pages'].json['properties']['Date']['date']['start'].includes('12:00:00') ? $node['Loop Over Notion Pages'].json['properties']['Date']['date']['start'].split('T')[0] : null)}}"
          }
        },
        "eventId": "{{$node['Loop Over Notion Pages'].json['properties']['Google Event ID']['rich_text'][0]['plain_text']}}"
      },
      "name": "Google Calendar Create/Update",
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1,
      "position": [
        900,
        300
      ],
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "authentication": "genericCredentialType",
        "resource": "page",
        "operation": "update",
        "pageId": "{{$node['Loop Over Notion Pages'].json['id']}}",
        "properties": {
          "Google Event ID": {
            "rich_text": [
              {
                "text": {
                  "content": "{{$node['Google Calendar Create/Update'].json['id']}}"
                }
              }
            ]
          }
        }
      },
      "name": "Notion Update Event ID",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        1120,
        300
      ],
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "url": "https://n8.velvetcld.kozow.com/webhook/google-calendar",
        "authentication": "none"
      },
      "name": "Google Calendar Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        240,
        600
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "event",
        "calendar": "85e8d827fde536807e1317e061a1fa3310c72c6050c933ec0e5d6e4df7bb96ee@group.calendar.google.com",
        "operation": "get",
        "eventId": "{{$node['Google Calendar Webhook'].json['eventId']}}"
      },
      "name": "Google Calendar Get Event",
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1,
      "position": [
        460,
        600
      ],
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "authentication": "genericCredentialType",
        "resource": "page",
        "operation": "{{$node['Google Calendar Get Event'].json['status'] === 'cancelled' ? 'delete' : ($node['Google Calendar Get Event'].json['notionPageId'] ? 'update' : 'create')}}",
        "databaseId": "24ddcbfd883580feab1dfa7270343d5b",
        "properties": {
          "Ac Name": {
            "title": [
              {
                "text": {
                  "content": "{{$node['Google Calendar Get Event'].json['summary']}}"
                }
              }
            ]
          },
          "Date": {
            "date": {
              "start": "{{$node['Google Calendar Get Event'].json['start']['dateTime'] || $node['Google Calendar Get Event'].json['start']['date']}}",
              "end": "{{$node['Google Calendar Get Event'].json['end']['dateTime'] || $node['Google Calendar Get Event'].json['end']['date'] || $node['Google Calendar Get Event'].json['start']['date']}}"
            }
          },
          "Google Event ID": {
            "rich_text": [
              {
                "text": {
                  "content": "{{$node['Google Calendar Get Event'].json['id']}}"
                }
              }
            ]
          }
        },
        "pageId": "{{$node['Google Calendar Get Event'].json['notionPageId']}}"
      },
      "name": "Notion Create/Update/Delete",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        680,
        600
      ],
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Notion Query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notion Query": {
      "main": [
        [
          {
            "node": "Loop Over Notion Pages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Notion Pages": {
      "main": [
        [
          {
            "node": "Google Calendar Create/Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Calendar Create/Update": {
      "main": [
        [
          {
            "node": "Notion Update Event ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Calendar Webhook": {
      "main": [
        [
          {
            "node": "Google Calendar Get Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Calendar Get Event": {
      "main": [
        [
          {
            "node": "Notion Create/Update/Delete",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}