{
  "name": "Notion and Google Calendar Sync",
  "nodes": [
    {
      "parameters": {
        "databaseId": "24ddcbfd883580feab1dfa7270343d5b",
        "resource": "database",
        "triggerOn": [
          "create",
          "update"
        ]
      },
      "name": "Notion Trigger",
      "type": "n8n-nodes-base.notionTrigger",
      "typeVersion": 1,
      "id": "e0b5d921-a532-4e94-a320-1b22e171b764",
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      },
      "position": [
        250,
        250
      ]
    },
    {
      "parameters": {
        "value1": "={{ $json.deleted }}",
        "options": {}
      },
      "name": "If Notion Item Deleted?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "id": "4e1837e2-45e0-466d-a197-2a5a544c2049",
      "position": [
        500,
        250
      ]
    },
    {
      "parameters": {
        "calendarId": "85e8d827fde536807e1317e061a1fa3310c72c6050c933ec0e5d6e4df7bb96ee@group.calendar.google.com",
        "eventId": "={{ $json.properties.gcal_id.rich_text[0].plain_text }}",
        "resource": "event",
        "operation": "delete"
      },
      "name": "Delete from Google Calendar",
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1,
      "id": "557a1b6c-82ce-4122-b5e1-95561a7a0b35",
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "position": [
        750,
        350
      ]
    },
    {
      "parameters": {
        "calendarId": "85e8d827fde536807e1317e061a1fa3310c72c6050c933ec0e5d6e4df7bb96ee@group.calendar.google.com",
        "eventId": "={{ $json.properties.gcal_id.rich_text[0].plain_text }}",
        "resource": "event",
        "operation": "get"
      },
      "name": "Get gcal_id from Notion",
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1,
      "id": "7b095932-d17b-4022-8178-5e4e7e6f9815",
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "position": [
        750,
        150
      ]
    },
    {
      "parameters": {
        "value1": "={{ $json.id }}",
        "options": {}
      },
      "name": "If Event Exists?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "id": "99335f4f-4d26-444f-83a3-a75d5a9d8212",
      "position": [
        1000,
        150
      ]
    },
    {
      "parameters": {
        "calendarId": "85e8d827fde536807e1317e061a1fa3310c72c6050c933ec0e5d6e4df7bb96ee@group.calendar.google.com",
        "eventId": "={{ $json.id }}",
        "resource": "event",
        "operation": "update",
        "updateFields": {
          "updateFields": [
            {
              "field": "summary",
              "value": "={{ $json.properties.Name.title[0].plain_text }}"
            },
            {
              "field": "start",
              "value": "={{ $json.properties.Date.date.start }}"
            },
            {
              "field": "end",
              "value": "={{ $json.properties.Date.date.end || $json.properties.Date.date.start }}"
            }
          ]
        }
      },
      "name": "Update Google Calendar Event",
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1,
      "id": "1e16f31e-45e3-4f93-b413-5a02e64c3a2f",
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "position": [
        1250,
        100
      ]
    },
    {
      "parameters": {
        "calendarId": "85e8d827fde536807e1317e061a1fa3310c72c6050c933ec0e5d6e4df7bb96ee@group.calendar.google.com",
        "resource": "event",
        "operation": "create",
        "summary": "={{ $json.properties.Name.title[0].plain_text }}",
        "start": "={{ $json.properties.Date.date.start }}",
        "end": "={{ $json.properties.Date.date.end || $json.properties.Date.date.start }}"
      },
      "name": "Create Google Calendar Event",
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1,
      "id": "2d14878b-3b32-429a-8b85-d28f09d849b2",
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "position": [
        1250,
        200
      ]
    },
    {
      "parameters": {
        "pageId": "={{ $json.id }}",
        "resource": "page",
        "operation": "update",
        "properties": {
          "gcal_id": {
            "type": "rich_text",
            "rich_text": {
              "content": "={{ $json.id }}"
            }
          }
        }
      },
      "name": "Update Notion with gcal_id",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "id": "6a9f4c39-4458-466d-a7b6-17b5e43a9d8c",
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      },
      "position": [
        1500,
        150
      ]
    },
    {
      "parameters": {
        "calendarId": "85e8d827fde536807e1317e061a1fa3310c72c6050c933ec0e5d6e4df7bb96ee@group.calendar.google.com",
        "resource": "event",
        "triggerOn": [
          "create",
          "update",
          "delete"
        ],
        "interval": 3
      },
      "name": "Google Calendar Trigger",
      "type": "n8n-nodes-base.googleCalendarTrigger",
      "typeVersion": 1,
      "id": "5f9a4e0a-40a2-4a0b-99d9-95e297a7a9a1",
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "position": [
        250,
        550
      ]
    },
    {
      "parameters": {
        "databaseId": "24ddcbfd883580feab1dfa7270343d5b",
        "resource": "page",
        "operation": "search",
        "filter": {
          "property": "gcal_id",
          "filter": "equals",
          "value": "={{ $json.id }}"
        }
      },
      "name": "Find Notion Page by gcal_id",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "id": "e7c65c4d-612b-42e1-8a6e-4e4b7b3b3a24",
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      },
      "position": [
        500,
        550
      ]
    },
    {
      "parameters": {
        "value1": "={{ $json.results.length }}",
        "options": {}
      },
      "name": "If Page Found?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "id": "8b584d43-5240-4e3f-91a1-9a7f34f378a8",
      "position": [
        750,
        550
      ]
    },
    {
      "parameters": {
        "pageId": "={{ $json.results[0].id }}",
        "resource": "page",
        "operation": "update",
        "properties": {
          "Name": {
            "type": "title",
            "title": {
              "content": "={{ $json.summary }}"
            }
          },
          "Date": {
            "type": "date",
            "date": {
              "start": "={{ $json.start.dateTime || $json.start.date }}",
              "end": "={{ $json.end.dateTime || $json.end.date }}"
            }
          }
        }
      },
      "name": "Update Notion Page",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "id": "b1b1c554-6663-4411-b1e9-467f5c7604d3",
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      },
      "position": [
        1000,
        500
      ]
    },
    {
      "parameters": {
        "databaseId": "24ddcbfd883580feab1dfa7270343d5b",
        "resource": "page",
        "operation": "create",
        "parentType": "database",
        "properties": {
          "Name": {
            "type": "title",
            "title": {
              "content": "={{ $json.summary }}"
            }
          },
          "Date": {
            "type": "date",
            "date": {
              "start": "={{ $json.start.dateTime || $json.start.date }}",
              "end": "={{ $json.end.dateTime || $json.end.date }}"
            }
          },
          "gcal_id": {
            "type": "rich_text",
            "rich_text": {
              "content": "={{ $json.id }}"
            }
          }
        }
      },
      "name": "Create Notion Page",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "id": "9982a170-c9a9-4a90-8e12-420a442e971a",
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      },
      "position": [
        1000,
        600
      ]
    }
  ],
  "connections": {
    "Notion Trigger": {
      "main": [
        [
          {
            "node": "If Notion Item Deleted?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Notion Item Deleted?": {
      "main": [
        [
          {
            "node": "Delete from Google Calendar",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get gcal_id from Notion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get gcal_id from Notion": {
      "main": [
        [
          {
            "node": "If Event Exists?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Event Exists?": {
      "main": [
        [
          {
            "node": "Update Google Calendar Event",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Google Calendar Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Google Calendar Event": {
      "main": [
        [
          {
            "node": "Update Notion with gcal_id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Google Calendar Event": {
      "main": [
        [
          {
            "node": "Update Notion with gcal_id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Calendar Trigger": {
      "main": [
        [
          {
            "node": "Find Notion Page by gcal_id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find Notion Page by gcal_id": {
      "main": [
        [
          {
            "node": "If Page Found?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Page Found?": {
      "main": [
        [
          {
            "node": "Update Notion Page",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Notion Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {},
  "staticData": null,
  "tags": [],
  "versionId": null,
  "id": "notion-google-sync-workflow"
}