I did it and found the mistake.
There was no data passed to the IF Function if the user was not existing yet.
This is the final version. Feel free to use it:
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
-770,
410
]
},
{
"parameters": {
"authentication": "oAuth2",
"operation": "getAll",
"limit": 1,
"options": {
"search": "={{$node[\"Set Webhook Request\"].json[\"email\"]}}"
}
},
"name": "Find User",
"type": "n8n-nodes-base.mautic",
"position": [
-430,
260
],
"notesInFlow": false,
"typeVersion": 1,
"alwaysOutputData": true,
"credentials": {
"mauticOAuth2Api": "Mautic"
}
},
{
"parameters": {
"keepOnlySet": true,
"values": {
"string": [
{
"name": "firstname",
"value": "Alex"
},
{
"name": "lastname",
"value": "test20212"
},
{
"name": "email",
"value": "[email protected]"
},
{
"name": "phone",
"value": "657432895678"
},
{
"name": "address_line_1",
"value": "TeststraĆe 28"
},
{
"name": "address_line_2"
},
{
"name": "city",
"value": "Testort"
},
{
"name": "zip_code",
"value": "1234"
},
{
"name": "product id",
"value": "3622"
},
{
"name": "status",
"value": "3622 processing"
},
{
"name": "last_order_date",
"value": "2021-01-04T12:03:24"
},
{
"name": "last_order_fulfilled"
},
{
"name": "attribution",
"value": "25"
},
{
"name": "newsletter",
"value": "1"
},
{
"name": "kvamodell",
"value": "DeLonghi PrimaDonna Soul"
},
{
"name": "kvamodell_custom"
}
],
"number": [],
"boolean": []
},
"options": {}
},
"name": "Set Webhook Request",
"type": "n8n-nodes-base.set",
"position": [
-580,
410
],
"typeVersion": 1
},
{
"parameters": {
"keepOnlySet": true,
"values": {
"string": [
{
"name": "userFound",
"value": "={{$node[\"If not found return -1\"].json[\"id\"]}}"
}
]
},
"options": {}
},
"name": "Set",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
-110,
250
]
},
{
"parameters": {
"functionCode": "items[0].json.id = items[0].json.id || -1\nreturn items;"
},
"name": "If not found return -1",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
-260,
250
]
},
{
"parameters": {
"mode": "mergeByIndex",
"join": "inner"
},
"name": "main customer data",
"type": "n8n-nodes-base.merge",
"typeVersion": 1,
"position": [
70,
390
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{$node[\"main customer data\"].json[\"userFound\"]}}",
"operation": "regex",
"value2": "-1"
}
]
}
},
"name": "IF NOT userFound",
"type": "n8n-nodes-base.if",
"position": [
280,
390
],
"typeVersion": 1,
"alwaysOutputData": false
},
{
"parameters": {
"authentication": "oAuth2",
"jsonParameters": true,
"bodyJson": "={\n\"email\" : \"{{$node[\"Set Webhook Request\"].json[\"email\"]}}\",\n\"firstname\" : \"{{$node[\"Set Webhook Request\"].json[\"firstname\"]}}\",\n\"lastname\" : \"{{$node[\"Set Webhook Request\"].json[\"lastname\"]}}\",\n\"address1\" : \"{{$node[\"Set Webhook Request\"].json[\"address_line_1\"]}}\",\n\"address2\" : \"{{$node[\"Set Webhook Request\"].json[\"address_line_2\"]}}\",\n\"city\" : \"{{$node[\"Set Webhook Request\"].json[\"city\"]}}\",\n\"zipcode\" : \"{{$node[\"Set Webhook Request\"].json[\"zip_code\"]}}\",\n\"phone\" : \"{{$node[\"Set Webhook Request\"].json[\"phone\"]}}\",\n\"newsletter\" : \"{{$node[\"Set Webhook Request\"].json[\"newsletter\"]}}\",\n\"kaffeevollautomat_modell\" : \"{{$node[\"Set Webhook Request\"].json[\"kvamodell\"]}}\",\n\"kaffeevollautomat_modell1\" : \"{{$node[\"Set Webhook Request\"].json[\"kvamodell_custom\"]}}\",\n\"ordered_products\" : \"{{$node[\"Set Webhook Request\"].json[\"product id\"]}}\",\n\"order_status\" : \"{{$node[\"Set Webhook Request\"].json[\"status\"]}}\",\n\"last_order_date\" : \"{{$node[\"Set Webhook Request\"].json[\"last_order_date\"]}}\",\n\"tags\" : \"{{$node[\"Set Webhook Request\"].json[\"product id\"]}}\"\n}",
"additionalFields": {},
"options": {
"rawData": false
}
},
"name": "Create New Contact",
"type": "n8n-nodes-base.mautic",
"position": [
510,
280
],
"typeVersion": 1,
"alwaysOutputData": false,
"credentials": {
"mauticOAuth2Api": "Mautic"
}
},
{
"parameters": {
"authentication": "oAuth2",
"operation": "update",
"contactId": "={{$node[\"Find User\"].json[\"id\"]}}",
"jsonParameters": true,
"updateFields": {
"bodyJson": "={\n\"firstname\" : \"{{$node[\"Set Webhook Request\"].json[\"firstname\"]}}\",\n\"lastname\" : \"{{$node[\"Set Webhook Request\"].json[\"lastname\"]}}\",\n\"address1\" : \"{{$node[\"Set Webhook Request\"].json[\"address_line_1\"]}}\",\n\"address2\" : \"{{$node[\"Set Webhook Request\"].json[\"address_line_2\"]}}\",\n\"city\" : \"{{$node[\"Set Webhook Request\"].json[\"city\"]}}\",\n\"zipcode\" : \"{{$node[\"Set Webhook Request\"].json[\"zip_code\"]}}\",\n\"phone\" : \"{{$node[\"Set Webhook Request\"].json[\"phone\"]}}\",\n\"newsletter\" : \"{{$node[\"Set Webhook Request\"].json[\"newsletter\"]}}\",\n\"kaffeevollautomat_modell\" : \"{{$node[\"Set Webhook Request\"].json[\"kvamodell\"]}}\",\n\"kaffeevollautomat_modell1\" : \"{{$node[\"Set Webhook Request\"].json[\"kvamodell_custom\"]}}\",\n\"ordered_products\" : \"{{$node[\"Set Webhook Request\"].json[\"product id\"]}}\",\n\"order_status\" : \"{{$node[\"Set Webhook Request\"].json[\"status\"]}}\",\n\"last_order_date\" : \"{{$node[\"Set Webhook Request\"].json[\"last_order_date\"]}}\",\n\"tags\" : \"{{$node[\"Set Webhook Request\"].json[\"product id\"]}}\"\n}"
},
"options": {
"rawData": false
}
},
"name": "Update existing contact",
"type": "n8n-nodes-base.mautic",
"position": [
510,
510
],
"typeVersion": 1,
"alwaysOutputData": false,
"credentials": {
"mauticOAuth2Api": "Mautic"
}
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "Set Webhook Request",
"type": "main",
"index": 0
}
]
]
},
"Find User": {
"main": [
[
{
"node": "If not found return -1",
"type": "main",
"index": 0
}
]
]
},
"Set Webhook Request": {
"main": [
[
{
"node": "main customer data",
"type": "main",
"index": 1
},
{
"node": "Find User",
"type": "main",
"index": 0
}
]
]
},
"Set": {
"main": [
[
{
"node": "main customer data",
"type": "main",
"index": 0
}
]
]
},
"If not found return -1": {
"main": [
[
{
"node": "Set",
"type": "main",
"index": 0
}
]
]
},
"main customer data": {
"main": [
[
{
"node": "IF NOT userFound",
"type": "main",
"index": 0
}
]
]
},
"IF NOT userFound": {
"main": [
[
{
"node": "Create New Contact",
"type": "main",
"index": 0
}
],
[
{
"node": "Update existing contact",
"type": "main",
"index": 0
}
]
]
}
}
}