{
  "nodes": [
    {
      "id": "119ed438-77b0-41b4-930d-177024233c13",
      "name": "Daily Cleanup Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "notes": "Triggers the daily deletion sync. Define the scheduler at your preferred interval.",
      "position": [
        1264,
        864
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 1.3
    },
    {
      "id": "9a43cfd5-402b-4925-b88b-98f450842e38",
      "name": "Delete contact",
      "type": "n8n-nodes-klicktipp.klicktipp",
      "notes": "Deletes the corresponding KlickTipp subscriber when a contact is removed from Salesforce.",
      "onError": "continueRegularOutput",
      "position": [
        2288,
        864
      ],
      "parameters": {
        "resource": "subscriber",
        "operation": "delete",
        "subscriberId": "={{ $json.records[0].KlickTipp_ID__c }}",
        "identifierType": "id"
      },
      "credentials": {
        "klickTippApi": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 3
    },
    {
      "id": "0acbdd3f-65f6-42a7-a039-4914b882e231",
      "name": "Contact tagged in KlickTipp",
      "type": "n8n-nodes-klicktipp.klicktippTrigger",
      "notes": "Triggers via KlickTipp webhook or Activation Tag.",
      "position": [
        1264,
        48
      ],
      "parameters": {
        "path": "c7f3e542-0814-4121-8b46-1cec97c277f7"
      },
      "credentials": {
        "klickTippApi": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "id": "31fbf0f5-2d0a-494b-a30b-315f34d0f414",
      "name": "Update Salesforce Contact",
      "type": "n8n-nodes-base.salesforce",
      "notes": "Updates existing Salesforce records with KlickTipp data.",
      "position": [
        2288,
        144
      ],
      "parameters": {
        "resource": "contact",
        "contactId": "={{ $('Contact tagged in KlickTipp').item.json.field227883}}",
        "operation": "update",
        "updateFields": {
          "email": "={{ $('Contact tagged in KlickTipp').item.json.email }}",
          "lastName": "={{ $('Contact tagged in KlickTipp').item.json.fieldLastName }}",
          "birthdate": "={{\n  DateTime\n    .fromMillis(\n      Number($('Contact tagged in KlickTipp').item.json.fieldBirthday) * 1000,\n      { zone: 'Europe/Berlin' }\n    )\n    .toFormat('yyyy-MM-dd')\n}}",
          "firstName": "={{ $('Contact tagged in KlickTipp').item.json.fieldFirstName }}",
          "mailingCity": "={{ $('Contact tagged in KlickTipp').item.json.fieldCity }}",
          "mobilePhone": "={{ $('Contact tagged in KlickTipp').item.json.fieldMobilePhone }}",
          "mailingStreet": "={{ $('Contact tagged in KlickTipp').item.json.fieldStreet1 }}",
          "customFieldsUi": {
            "customFieldsValues": [
              {
                "value": "={{ $('Contact tagged in KlickTipp').item.json.status }}",
                "fieldId": "KlickTipp_marketing_status__c"
              }
            ]
          }
        }
      },
      "credentials": {
        "salesforceOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "id": "a7f67f98-d129-4ef2-896b-e694925d9347",
      "name": "Create Salesforce Contact",
      "type": "n8n-nodes-base.salesforce",
      "notes": "Creates a new Salesforce contact if it doesn't already exist.",
      "position": [
        2288,
        -48
      ],
      "parameters": {
        "lastname": "={{ $('Contact tagged in KlickTipp').item.json.fieldLastName }}",
        "resource": "contact",
        "additionalFields": {
          "email": "={{ $('Contact tagged in KlickTipp').item.json.email }}",
          "birthdate": "={{\n  DateTime\n    .fromMillis(\n      Number($('Contact tagged in KlickTipp').item.json.fieldBirthday) * 1000,\n      { zone: 'Europe/Berlin' }\n    )\n    .toFormat('yyyy-MM-dd')\n}}",
          "firstName": "={{ $('Contact tagged in KlickTipp').item.json.fieldFirstName }}",
          "mailingCity": "={{ $('Contact tagged in KlickTipp').item.json.fieldCity }}",
          "mobilePhone": "={{ $('Contact tagged in KlickTipp').item.json.fieldMobilePhone }}",
          "mailingStreet": "={{ $('Contact tagged in KlickTipp').item.json.fieldStreet1 }}",
          "customFieldsUi": {
            "customFieldsValues": [
              {
                "value": "={{ $('Contact tagged in KlickTipp').item.json.id }}",
                "fieldId": "KlickTipp_ID__c"
              },
              {
                "value": "={{ $('Contact tagged in KlickTipp').item.json.status }}",
                "fieldId": "KlickTipp_marketing_status__c"
              }
            ]
          },
          "mailingPostalCode": "={{ $('Contact tagged in KlickTipp').item.json.fieldZip }}"
        }
      },
      "credentials": {
        "salesforceOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "id": "543d1541-f49f-48c2-addc-6f1ee85062bb",
      "name": "New Salesforce Contact",
      "type": "n8n-nodes-base.salesforceTrigger",
      "notes": "Triggers when a new contact is created in Salesforce.",
      "position": [
        1264,
        336
      ],
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "contactCreated"
      },
      "credentials": {
        "salesforceOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "id": "e6d5b3f3-b9d8-420b-b64a-66de3af7131e",
      "name": "Updated Salesforce Contact",
      "type": "n8n-nodes-base.salesforceTrigger",
      "notes": "Triggers when a contact is modified in Salesforce.",
      "position": [
        1264,
        528
      ],
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "contactUpdated"
      },
      "credentials": {
        "salesforceOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "id": "846fe9e2-3edd-4674-8cdf-2d6492ac5e2b",
      "name": "Data Normalization & Mapping",
      "type": "n8n-nodes-base.set",
      "notes": "Maps Salesforce fields to KlickTipp variables and converts dates to Unix timestamps.",
      "position": [
        1488,
        432
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d32147a0-bc6b-49f1-a072-0b0d1056ed69",
              "name": "KlickTipp_ID",
              "type": "string",
              "value": "={{ $json.KlickTipp_ID__c }}"
            },
            {
              "id": "00696b72-f790-4fde-b950-ed983fa5cb9c",
              "name": "Email",
              "type": "string",
              "value": "={{ $json.Email }}"
            },
            {
              "id": "b0d2e9f9-9985-48f9-a22c-8331+1234567890",
              "name": "First_name",
              "type": "string",
              "value": "={{ $json.FirstName }}"
            },
            {
              "id": "b98a6a4a-1f5e-420a-9b97-45725875fd6b",
              "name": "Last_name",
              "type": "string",
              "value": "={{ $json.LastName }}"
            },
            {
              "id": "90440e0f-a5f5-4f99-863a-15a84b7cdace",
              "name": "Birthday",
              "type": "string",
              "value": "={{\n  (() => {\n    const birthday = $json.Birthdate;\n    if (!birthday) return '';\n    const dateObject = new Date(birthday);\n    return Math.floor(dateObject.getTime() / 1000);\n  })()\n}}"
            },
            {
              "id": "40b927c3-6012-4728-afd7-b740454ed9c5",
              "name": "Salesforce_ID",
              "type": "string",
              "value": "={{ $json.Id }}"
            },
            {
              "id": "79c047cf-9fc2-42fb-a569-aa48a1b867e4",
              "name": "KlickTipp_ID_exists",
              "type": "boolean",
              "value": "={{ !!$json.KlickTipp_ID__c && $json.KlickTipp_ID__c.toString().trim() !== '' }}"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 3.4
    },
    {
      "id": "410ca368-c7b5-481e-9b02-393c03ef4af0",
      "name": "Fetch Deleted SF Contacts",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "Queries Salesforce for records deleted within the last 24 hours.",
      "position": [
        1488,
        864
      ],
      "parameters": {
        "url": "https://orgfarm-0c137263ea-dev-ed.develop.my.salesforce.com/services/data//v59.0/queryAll",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "q",
              "value": "SELECT Id, Email, SystemModstamp, KlickTipp_ID__c FROM Contact WHERE IsDeleted = true AND Email != null AND SystemModstamp = LAST_N_DAYS:1 ORDER BY SystemModstamp DESC"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "salesforceOAuth2Api"
      },
      "credentials": {
        "salesforceOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.3
    },
    {
      "id": "5100372d-510c-4fdb-acae-4a7e7bfdd215",
      "name": "Get KlickTipp Tags",
      "type": "n8n-nodes-klicktipp.klicktipp",
      "notes": "Retrieves current subscriber tags for segmentation processing.",
      "position": [
        3136,
        48
      ],
      "parameters": {
        "resource": "subscriber",
        "operation": "get",
        "subscriberId": "={{ $('Contact tagged in KlickTipp').item.json.id }}",
        "identifierType": "id"
      },
      "credentials": {
        "klickTippApi": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 3
    },
    {
      "id": "85f11fe5-5f94-4229-b53f-46992ebe1def",
      "name": "Assign SF Topic (Customer)",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "Maps the 'Customer' segment from KlickTipp to Salesforce Topics.",
      "onError": "continueRegularOutput",
      "position": [
        3632,
        -48
      ],
      "parameters": {
        "url": "https://orgfarm-0c137263ea-dev-ed.develop.my.salesforce.com/services/data/v60.0/sobjects/TopicAssignment",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"TopicId\": \"0TOfj000000GO9dGAG\",\n  \"EntityId\": \"{{ $('Create a contact').item.json.id }}\"\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "salesforceOAuth2Api"
      },
      "credentials": {
        "salesforceOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.3
    },
    {
      "id": "53f2f2e1-2f21-4933-a4cf-37de2c087fbc",
      "name": "Assign SF Topic (ABC)",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "Maps the 'ABC' segment from KlickTipp to Salesforce Topics.",
      "onError": "continueRegularOutput",
      "position": [
        3632,
        144
      ],
      "parameters": {
        "url": "https://orgfarm-0c137263ea-dev-ed.develop.my.salesforce.com/services/data/v60.0/sobjects/TopicAssignment",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"TopicId\": \"0TOfj000000GOG5GAO\",\n  \"EntityId\": \"{{ $('Create a contact').item.json.id }}\"\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "salesforceOAuth2Api"
      },
      "credentials": {
        "salesforceOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.3
    },
    {
      "id": "b8069876-4b93-4c91-a8ab-5fc71e518d64",
      "name": "Sync SF ID to KlickTipp",
      "type": "n8n-nodes-klicktipp.klicktipp",
      "notes": "Stores the Salesforce Contact ID back into the KlickTipp custom field for 2-way sync.",
      "position": [
        2592,
        -48
      ],
      "parameters": {
        "fields": {
          "dataFields": [
            {
              "fieldId": "field227883",
              "fieldValue": "={{ $json.id }}"
            }
          ]
        },
        "resource": "subscriber",
        "operation": "update",
        "subscriberId": "={{ $('Contact tagged in KlickTipp').item.json.id }}",
        "identifierType": "id"
      },
      "credentials": {
        "klickTippApi": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 3
    },
    {
      "id": "2e1d5973-7fb9-44c7-85fc-933f92592dad",
      "name": "Create KlickTipp Subscriber",
      "type": "n8n-nodes-klicktipp.klicktipp",
      "notes": "Creates a new subscriber in KlickTipp with the Single Opt-In process.",
      "position": [
        2288,
        352
      ],
      "parameters": {
        "email": "={{ $('Data Normalization & Mapping').item.json.Email }}",
        "tagId": "14041983",
        "fields": {
          "dataFields": [
            {
              "fieldId": "fieldFirstName",
              "fieldValue": "={{ $('Data Normalization & Mapping').item.json.First_name }}"
            },
            {
              "fieldId": "fieldLastName",
              "fieldValue": "={{ $('Data Normalization & Mapping').item.json.Last_name }}"
            },
            {
              "fieldId": "fieldBirthday",
              "fieldValue": "={{ $('Data Normalization & Mapping').item.json.Birthday }}"
            },
            {
              "fieldId": "field227883",
              "fieldValue": "={{ $('Data Normalization & Mapping').item.json.Salesforce_ID }}"
            }
          ]
        },
        "listId": "364353",
        "resource": "subscriber",
        "operation": "subscribe"
      },
      "credentials": {
        "klickTippApi": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 3
    },
    {
      "id": "a35ac217-33d3-4b84-94df-ac6cbbeb6d59",
      "name": "Sync KlickTipp ID to SF",
      "type": "n8n-nodes-base.salesforce",
      "notes": "Updates Salesforce with the KlickTipp ID for record matching.",
      "position": [
        2592,
        352
      ],
      "parameters": {
        "resource": "contact",
        "contactId": "={{ $('Data Normalization & Mapping').item.json.Salesforce_ID}}",
        "operation": "update",
        "updateFields": {
          "customFieldsUi": {
            "customFieldsValues": [
              {
                "value": "={{ $json.id }}",
                "fieldId": "KlickTipp_ID__c"
              },
              {
                "value": "Subscribed",
                "fieldId": "KlickTipp_marketing_status__c"
              }
            ]
          }
        }
      },
      "credentials": {
        "salesforceOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "id": "e955a79f-0b7d-40a8-bcf4-630b0914e251",
      "name": "Update KlickTipp Subscriber",
      "type": "n8n-nodes-klicktipp.klicktipp",
      "notes": "Syncs Salesforce updates to the corresponding KlickTipp subscriber.",
      "position": [
        2288,
        528
      ],
      "parameters": {
        "email": "={{ $('Data Normalization & Mapping').item.json.Email }}",
        "fields": {
          "dataFields": [
            {
              "fieldId": "fieldFirstName",
              "fieldValue": "={{ $('Data Normalization & Mapping').item.json.First_name }}"
            },
            {
              "fieldId": "fieldLastName",
              "fieldValue": "={{ $('Data Normalization & Mapping').item.json.Last_name }}"
            },
            {
              "fieldId": "fieldBirthday",
              "fieldValue": "={{ $('Data Normalization & Mapping').item.json.Birthday }}"
            },
            {
              "fieldId": "field227685",
              "fieldValue": "={{ $('Data Normalization & Mapping').item.json.Salesforce_ID }}"
            }
          ]
        },
        "resource": "subscriber",
        "operation": "update",
        "subscriberId": "={{ $('Data Normalization & Mapping').item.json.KlickTipp_ID }}",
        "identifierType": "id"
      },
      "credentials": {
        "klickTippApi": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 3
    },
    {
      "id": "6a1aad07-86e9-4226-840d-68a0aeb8c158",
      "name": "Get Salesforce Topics",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "Fetches assigned Salesforce Topics to sync back to KlickTipp Tags.",
      "position": [
        3136,
        432
      ],
      "parameters": {
        "url": "https://orgfarm-0c137263ea-dev-ed.develop.my.salesforce.com/services/data//v60.0/query",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "q",
              "value": "=SELECT TopicId, Topic.Name FROM TopicAssignment WHERE EntityId = '{{ $('Data Normalization & Mapping').item.json.Salesforce_ID }}'"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "salesforceOAuth2Api"
      },
      "credentials": {
        "salesforceOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.3
    },
    {
      "id": "26cfaf48-36e2-442d-83df-0a3aeded0dde",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1216,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 448,
        "height": 1552,
        "content": "## 1. Get contact data."
      },
      "typeVersion": 1
    },
    {
      "id": "914171d2-79be-4402-aaee-612ef3397dd2",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1936,
        -160
      ],
      "parameters": {
        "color": 7,
        "height": 1552,
        "content": "## 3. Route by subscription."
      },
      "typeVersion": 1
    },
    {
      "id": "5ea09d98-39ca-46e3-b7ad-44a8d0f1c87e",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2192,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 304,
        "height": 1552,
        "content": "## 4. Transfer contact data."
      },
      "typeVersion": 1
    },
    {
      "id": "a367b711-56a6-41ce-b4eb-0bf678aaa52a",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2512,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 544,
        "height": 1552,
        "content": "## 5. Save IDs & Status"
      },
      "typeVersion": 1
    },
    {
      "id": "c99deb8d-a984-4463-bce5-52c888434fcb",
      "name": "Sticky Note15",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3072,
        -160
      ],
      "parameters": {
        "color": 7,
        "height": 1552,
        "content": "## 6. Get full contact"
      },
      "typeVersion": 1
    },
    {
      "id": "fb6d5233-ebea-4acb-a4e2-50636c89cce4",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3328,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 496,
        "height": 1552,
        "content": "## 7. Segmentation."
      },
      "typeVersion": 1
    },
    {
      "id": "c2c7ae37-427d-4305-8514-658ac29aaf14",
      "name": "Salesforce Lookup Switch",
      "type": "n8n-nodes-base.if",
      "notes": "Determines if a Salesforce record exists by checking for a stored ID.",
      "position": [
        2000,
        48
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "5bbda628-9903-4207-b3e8-74eba3dc34ef",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ !$json.field227883 }}",
              "rightValue": ""
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 2.3
    },
    {
      "id": "346001ed-29c1-4fc3-a86f-40f4bb977243",
      "name": "KlickTipp Lookup Switch",
      "type": "n8n-nodes-base.if",
      "notes": "Checks if the contact is already registered in KlickTipp.",
      "position": [
        2000,
        432
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "5bbda628-9903-4207-b3e8-74eba3dc34ef",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              },
              "leftValue": "={{ $('Data Normalization & Mapping').item.json.KlickTipp_ID_exists }}",
              "rightValue": "Contact ID is missing"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 2.3
    },
    {
      "id": "3a40badc-616d-4b3c-87fb-f11bd31cf77c",
      "name": "Documentation Sticky",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        -160
      ],
      "parameters": {
        "width": 727,
        "height": 416,
        "content": "## How it works\nThis workflow creates a two-way synchronization between **KlickTipp** and **Salesforce Contacts**. Whenever a contact is created, updated, or deleted, the changes are mirrored across both platforms.\n\n* **KlickTipp \u2192 Salesforce**: Triggered by webhooks, it creates or updates Salesforce records and stores the reference IDs.\n* **Salesforce \u2192 KlickTipp**: Monitors Contact changes, normalizes data (like Birthdays), and syncs them to KlickTipp subscribers.\n* **GDPR Cleanup**: A daily schedule removes deleted Salesforce contacts from KlickTipp automatically.\n\n## Setup steps\n1.  **Salesforce Fields**: Create a custom field `KlickTipp_ID__c` on the Contact object.\n2.  **KlickTipp Fields**: Create a custom field for the Salesforce ID (mapped here to `field227883`).\n3.  **Credentials**: Connect your Salesforce OAuth2 and KlickTipp API accounts.\n4.  **URLs**: Update the HTTP Request nodes with your specific Salesforce instance URL.\n5.  **Topics**: Map your Salesforce Topic IDs in the segmentation branch."
      },
      "typeVersion": 1
    },
    {
      "id": "c845f605-2777-4e24-978c-d2d36b2a460d",
      "name": "Segment Matcher (SF to KT)",
      "type": "n8n-nodes-base.switch",
      "notes": "Determines which KlickTipp tags to apply based on Salesforce Topics.",
      "position": [
        3392,
        608
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Topic Customer exists",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "0d2c4065-885b-4ada-b262-ffdc2f18b179",
                    "operator": {
                      "type": "array",
                      "operation": "contains",
                      "rightType": "any"
                    },
                    "leftValue": "={{\n  $('Get Salesforce Topics').item.json.records\n    .filter(record => record.Topic && record.Topic.Name)\n    .map(record => record.Topic.Name)\n}}",
                    "rightValue": "Customer"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Topic ABC exists",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c7043274-dcbb-4675-95cd-4dbed9e62436",
                    "operator": {
                      "type": "array",
                      "operation": "contains",
                      "rightType": "any"
                    },
                    "leftValue": "={{\n  $('Get Salesforce Topics').item.json.records\n    .filter(record => record.Topic && record.Topic.Name)\n    .map(record => record.Topic.Name)\n}}",
                    "rightValue": "ABC"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "allMatchingOutputs": true
        }
      },
      "notesInFlow": true,
      "typeVersion": 3.4
    },
    {
      "id": "030a8e68-8ddc-44f1-bd8f-a28a1ffe3adb",
      "name": "Segment Matcher (KT to SF)",
      "type": "n8n-nodes-base.switch",
      "notes": "Determines which Salesforce topics to assign based on KlickTipp tags.",
      "position": [
        3392,
        48
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Contact has Tag Customer",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c4dc411e-1e5d-427e-9c11-c04236641496",
                    "operator": {
                      "type": "array",
                      "operation": "contains",
                      "rightType": "any"
                    },
                    "leftValue": "={{ $('Get KlickTipp Tags').item.json.tags }}",
                    "rightValue": "14061012"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Contact has Tag ABC",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "d3791564-1858-4dd1-a56b-34a64f92ccda",
                    "operator": {
                      "type": "array",
                      "operation": "contains",
                      "rightType": "any"
                    },
                    "leftValue": "={{ $('Get KlickTipp Tags').item.json.tags }}",
                    "rightValue": "14061060"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "allMatchingOutputs": true
        }
      },
      "notesInFlow": true,
      "typeVersion": 3.4
    },
    {
      "id": "1bae0c48-1e79-4b26-9e85-d20203d8f48c",
      "name": "Apply Tag: Customer",
      "type": "n8n-nodes-klicktipp.klicktipp",
      "notes": "Tags the contact as a 'Customer' in KlickTipp.",
      "position": [
        3632,
        512
      ],
      "parameters": {
        "email": "={{ $('Data Normalization & Mapping').item.json.Email }}",
        "tagId": [
          "14061012"
        ],
        "resource": "contact-tagging"
      },
      "credentials": {
        "klickTippApi": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 3
    },
    {
      "id": "5f2bff09-fe9b-4a3b-ab67-9000dcf30834",
      "name": "Apply Tag: ABC",
      "type": "n8n-nodes-klicktipp.klicktipp",
      "notes": "Tags the contact as 'ABC' in KlickTipp.",
      "position": [
        3632,
        704
      ],
      "parameters": {
        "email": "={{ $('Data Normalization & Mapping').item.json.Email }}",
        "tagId": [
          "14061060"
        ],
        "resource": "contact-tagging"
      },
      "credentials": {
        "klickTippApi": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 3
    },
    {
      "id": "c2981943-5690-408a-972d-bbcfe5ced62d",
      "name": "Apply Default Tag",
      "type": "n8n-nodes-klicktipp.klicktipp",
      "notes": "Applies the primary sync tag in KlickTipp.",
      "position": [
        3632,
        352
      ],
      "parameters": {
        "email": "={{ $('Data Normalization & Mapping').item.json.Email }}",
        "tagId": [
          "14152706"
        ],
        "resource": "contact-tagging"
      },
      "credentials": {
        "klickTippApi": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 3
    },
    {
      "id": "e7e0c6ed-8aaf-4da6-90cc-170dd5122837",
      "name": "GDPR Deletion Request Trigger",
      "type": "n8n-nodes-klicktipp.klicktippTrigger",
      "notes": "Triggers when a user clicks the data deletion link in an email.",
      "position": [
        1264,
        1152
      ],
      "parameters": {},
      "credentials": {
        "klickTippApi": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "id": "898ae321-5d52-4ec3-ad91-bf002b10d904",
      "name": "Is SF Link Present?",
      "type": "n8n-nodes-base.filter",
      "notes": "Ensures deletion only attempts to run in Salesforce if a Contact ID is linked.",
      "position": [
        1760,
        1152
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "fd5e83c0-d61e-459f-9420-45ecbc7fbfe8",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.field227883 }}",
              "rightValue": ""
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 2.3
    },
    {
      "id": "5247f3f0-da1f-41de-bbe5-efc6c23b26a9",
      "name": "GDPR Delete Salesforce Contact",
      "type": "n8n-nodes-base.salesforce",
      "notes": "Permanently removes the contact from Salesforce to comply with GDPR requests.",
      "position": [
        2288,
        1152
      ],
      "parameters": {
        "resource": "contact",
        "contactId": "={{ $('GDPR Deletion Request Trigger').item.json.field227883 }}",
        "operation": "delete"
      },
      "credentials": {
        "salesforceOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "id": "0aa8e11c-e8f9-4c29-924b-3ba2a28e08a2",
      "name": "Check Subscription Status",
      "type": "n8n-nodes-klicktipp.klicktipp",
      "notes": "Verifies the current opt-in status in KlickTipp.",
      "position": [
        2592,
        528
      ],
      "parameters": {
        "resource": "subscriber",
        "operation": "get",
        "subscriberId": "={{ $('Data Normalization & Mapping').item.json.KlickTipp_ID}}",
        "identifierType": "id"
      },
      "credentials": {
        "klickTippApi": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 3
    },
    {
      "id": "709efe4a-2669-4489-a432-e0c22689349f",
      "name": "Sync Marketing Status to SF",
      "type": "n8n-nodes-base.salesforce",
      "notes": "Updates Salesforce with the current marketing/consent status.",
      "position": [
        2816,
        528
      ],
      "parameters": {
        "resource": "contact",
        "contactId": "={{ $('Data Normalization & Mapping').item.json.Salesforce_ID}}",
        "operation": "update",
        "updateFields": {
          "customFieldsUi": {
            "customFieldsValues": [
              {
                "value": "={{ $json.status }}",
                "fieldId": "KlickTipp_marketing_status__c"
              }
            ]
          }
        }
      },
      "credentials": {
        "salesforceOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "id": "888ffad8-10fd-4220-a7e8-64425185acca",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1680,
        -160
      ],
      "parameters": {
        "color": 7,
        "height": 1552,
        "content": "## 2. Filter\n"
      },
      "typeVersion": 1
    },
    {
      "id": "45d976d7-2667-499b-9b99-bc7fae478a0f",
      "name": "Ignore API Auto-Updates",
      "type": "n8n-nodes-base.filter",
      "notes": "Prevents infinite loops by ignoring changes made by the integration's own API user.",
      "position": [
        1760,
        432
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c9930c45-3594-40fb-b065-f563f2506428",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $('Updated Salesforce Contact').item.json.LastModifiedById }}",
              "rightValue": "005fj00000AdU0UAAV"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 2.3
    }
  ],
  "connections": {
    "Get KlickTipp Tags": {
      "main": [
        [
          {
            "node": "Segment Matcher (KT to SF)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is SF Link Present?": {
      "main": [
        [
          {
            "node": "GDPR Delete Salesforce Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Cleanup Trigger": {
      "main": [
        [
          {
            "node": "Fetch Deleted SF Contacts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Salesforce Topics": {
      "main": [
        [
          {
            "node": "Segment Matcher (SF to KT)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "New Salesforce Contact": {
      "main": [
        [
          {
            "node": "Data Normalization & Mapping",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ignore API Auto-Updates": {
      "main": [
        [
          {
            "node": "KlickTipp Lookup Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "KlickTipp Lookup Switch": {
      "main": [
        [
          {
            "node": "Create KlickTipp Subscriber",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update KlickTipp Subscriber",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sync KlickTipp ID to SF": {
      "main": [
        [
          {
            "node": "Get Salesforce Topics",
            "type": "main",
            "index": 0
          },
          {
            "node": "Apply Default Tag",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sync SF ID to KlickTipp": {
      "main": [
        [
          {
            "node": "Get KlickTipp Tags",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Salesforce Lookup Switch": {
      "main": [
        [
          {
            "node": "Create Salesforce Contact",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update Salesforce Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Subscription Status": {
      "main": [
        [
          {
            "node": "Sync Marketing Status to SF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Salesforce Contact": {
      "main": [
        [
          {
            "node": "Sync SF ID to KlickTipp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Deleted SF Contacts": {
      "main": [
        [
          {
            "node": "Delete contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Salesforce Contact": {
      "main": [
        [
          {
            "node": "Get KlickTipp Tags",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Segment Matcher (KT to SF)": {
      "main": [
        [
          {
            "node": "Assign SF Topic (Customer)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Assign SF Topic (ABC)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Segment Matcher (SF to KT)": {
      "main": [
        [
          {
            "node": "Apply Tag: Customer",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Apply Tag: ABC",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Updated Salesforce Contact": {
      "main": [
        [
          {
            "node": "Data Normalization & Mapping",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Contact tagged in KlickTipp": {
      "main": [
        [
          {
            "node": "Salesforce Lookup Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create KlickTipp Subscriber": {
      "main": [
        [
          {
            "node": "Sync KlickTipp ID to SF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sync Marketing Status to SF": {
      "main": [
        [
          {
            "node": "Get Salesforce Topics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update KlickTipp Subscriber": {
      "main": [
        [
          {
            "node": "Check Subscription Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Data Normalization & Mapping": {
      "main": [
        [
          {
            "node": "Ignore API Auto-Updates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GDPR Deletion Request Trigger": {
      "main": [
        [
          {
            "node": "Is SF Link Present?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}