{
  "nodes": [
    {
      "name": "Extract Name and Email",
      "type": "n8n-nodes-base.set",
      "position": [
        950,
        130
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "Name",
              "value": "={{$json[\"body\"][\"name\"]}}"
            },
            {
              "name": "Email",
              "value": "={{$json[\"body\"][\"email\"]}}"
            }
          ],
          "boolean": []
        },
        "options": {},
        "keepOnlySet": true
      },
      "typeVersion": 1
    },
    {
      "name": "Sign Up",
      "type": "n8n-nodes-base.webhook",
      "notes": "Example Input Data: {\"name\":\"John Doe\",\"email\":\"user@example.com\"}",
      "position": [
        720,
        130
      ],
      "parameters": {
        "path": "sign-up",
        "options": {
          "responseData": ""
        },
        "httpMethod": "POST",
        "authentication": "basicAuth"
      },
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "name": "If user exists",
      "type": "n8n-nodes-base.if",
      "position": [
        1560,
        150
      ],
      "parameters": {
        "conditions": {
          "string": [],
          "boolean": [
            {
              "value1": "={{Object.keys($json).includes(\"id\") }}",
              "value2": true
            }
          ]
        }
      },
      "executeOnce": false,
      "typeVersion": 1,
      "alwaysOutputData": false
    },
    {
      "name": "Create User",
      "type": "n8n-nodes-base.notion",
      "position": [
        1750,
        240
      ],
      "parameters": {
        "resource": "databasePage",
        "databaseId": "REPLACE_WITH_DATABASEID",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "REPLACE_WITH_KEY",
              "title": "={{$json[\"Name\"]}}"
            },
            {
              "key": "REPLACE_WITH_KEY",
              "emailValue": "={{$json[\"Email\"]}}"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "name": "Query for User",
      "type": "n8n-nodes-base.notion",
      "position": [
        1150,
        230
      ],
      "parameters": {
        "options": {
          "filter": {
            "singleCondition": {
              "key": "REPLACE_WITH_KEY",
              "condition": "equals",
              "emailValue": "={{$json[\"Email\"]}}"
            }
          }
        },
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "REPLACE_WITH_DATABASEID"
      },
      "executeOnce": false,
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "name": "Query Current Semester",
      "type": "n8n-nodes-base.notion",
      "position": [
        2180,
        -30
      ],
      "parameters": {
        "options": {
          "sort": {
            "sortValue": [
              {
                "key": "REPLACE_WITH_KEY",
                "direction": "descending",
                "timestamp": true
              }
            ]
          },
          "filter": {
            "singleCondition": {
              "key": "REPLACE_WITH_KEY",
              "condition": "equals",
              "checkboxValue": true
            }
          }
        },
        "resource": "databasePage",
        "operation": "getAll",
        "returnAll": true,
        "databaseId": "REPLACE_WITH_DATABASEID"
      },
      "typeVersion": 1
    },
    {
      "name": "Select Semester ID",
      "type": "n8n-nodes-base.set",
      "position": [
        2370,
        -30
      ],
      "parameters": {
        "values": {
          "number": [],
          "string": [
            {
              "name": "currentSemesterID",
              "value": "={{$json[\"id\"]}}"
            }
          ]
        },
        "options": {},
        "keepOnlySet": true
      },
      "typeVersion": 1
    },
    {
      "name": "Update Semester for User",
      "type": "n8n-nodes-base.notion",
      "position": [
        3050,
        110
      ],
      "parameters": {
        "pageId": "={{$json[\"id\"]}}",
        "resource": "databasePage",
        "operation": "update",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "REPLACE_WITH_KEY",
              "relationValue": [
                "={{$json[\"allSemesterIDs\"].join(',')}}"
              ]
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "name": "Merge Semester ID",
      "type": "n8n-nodes-base.merge",
      "position": [
        2590,
        110
      ],
      "parameters": {
        "mode": "multiplex"
      },
      "typeVersion": 1
    },
    {
      "name": "Concatenate Semester IDs",
      "type": "n8n-nodes-base.function",
      "position": [
        2820,
        110
      ],
      "parameters": {
        "functionCode": "for (item of items) {\n  // Get the current semester ID\n  const currentSemesterID = item.json[\"currentSemesterID\"]\n  let allSemesterIDs = [currentSemesterID];\n\n  // Add semesters that the user is already associated with\n  if (item.json[\"Semesters\"]?.length > 0) {\n    allSemesterIDs = allSemesterIDs.concat(item.json[\"Semesters\"].filter(semesterID => semesterID !== currentSemesterID));\n  }\n\n  // Set allSemesterIDs which is used to update the relation\n  item.json[\"allSemesterIDs\"] = allSemesterIDs\n}\n\nreturn items;\n"
      },
      "typeVersion": 1
    },
    {
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        1340,
        150
      ],
      "parameters": {
        "mode": "mergeByKey",
        "propertyName1": "Email",
        "propertyName2": "Email"
      },
      "typeVersion": 1
    },
    {
      "name": "Query User",
      "type": "n8n-nodes-base.notion",
      "position": [
        1950,
        130
      ],
      "parameters": {
        "options": {
          "filter": {
            "singleCondition": {
              "key": "REPLACE_WITH_KEY",
              "condition": "equals",
              "emailValue": "={{$json[\"Email\"]}}"
            }
          }
        },
        "resource": "databasePage",
        "operation": "getAll",
        "returnAll": true,
        "databaseId": "REPLACE_WITH_DATABASEID"
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "9a77ca83-ce2a-5778-882d-1fd4229c6aa5",
      "name": "Publication · Overview and setup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -800,
        -30
      ],
      "parameters": {
        "content": "# webhook and notion and list database page notion\n\n## Purpose and structure\nThis folder contains the **webhook and notion and list database page notion** workflow. Its executable nodes use `function`, `if`, `merge`, `notion`, `set`, `webhook`. The table and connection map below are derived from the JSON, not an inferred guarantee of behavior.\n\n## Setup\nImport inactive. Configure your own credentials and replace REPLACE_WITH_* values. Review external destinations and Code nodes before running.\n\n## Entry points\nSign Up\n\n## Verification\nSanitized source candidate; not runtime-tested. This overview is generated from node metadata. Read the folder README for the connection map, credential types, and license.\n\n## Attribution\nhttps://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Notion/0141_Notion_Webhook_Create_Webhook.json\nMIT; preserve source notices.",
        "width": 700,
        "height": 800,
        "color": 1
      }
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "If user exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sign Up": {
      "main": [
        [
          {
            "node": "Extract Name and Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Query User": {
      "main": [
        [
          {
            "node": "Query Current Semester",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge Semester ID",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Create User": {
      "main": [
        [
          {
            "node": "Query User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If user exists": {
      "main": [
        [
          {
            "node": "Query User",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Query for User": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge Semester ID": {
      "main": [
        [
          {
            "node": "Concatenate Semester IDs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select Semester ID": {
      "main": [
        [
          {
            "node": "Merge Semester ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Name and Email": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          },
          {
            "node": "Query for User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Query Current Semester": {
      "main": [
        [
          {
            "node": "Select Semester ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Concatenate Semester IDs": {
      "main": [
        [
          {
            "node": "Update Semester for User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false
}
