{
  "name": "Chatwoot - Search and Update Contact",
  "nodes": [
    {
      "parameters": {},
      "id": "start-node",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "resource": "contact",
        "operation": "search",
        "query": "john@example.com",
        "returnAll": false,
        "limit": 1
      },
      "id": "chatwoot-search",
      "name": "Search Contact by Email",
      "type": "n8n-nodes-chatwoot.chatwoot",
      "typeVersion": 1,
      "position": [
        450,
        300
      ],
      "credentials": {
        "chatwootApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.id }}",
              "operation": "isNotEmpty"
            }
          ]
        }
      },
      "id": "if-found",
      "name": "Contact Found?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "resource": "contact",
        "operation": "update",
        "contactId": "={{ $json.id }}",
        "updateFields": {
          "name": "John Doe Updated",
          "custom_attributes": "{\"vip\": true, \"updated_via\": \"n8n\"}"
        }
      },
      "id": "chatwoot-update",
      "name": "Update Contact",
      "type": "n8n-nodes-chatwoot.chatwoot",
      "typeVersion": 1,
      "position": [
        850,
        200
      ],
      "credentials": {
        "chatwootApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "contact",
        "operation": "create",
        "inboxId": 1,
        "name": "John Doe",
        "additionalFields": {
          "email": "john@example.com",
          "phone_number": "+1234567890"
        }
      },
      "id": "chatwoot-create",
      "name": "Create New Contact",
      "type": "n8n-nodes-chatwoot.chatwoot",
      "typeVersion": 1,
      "position": [
        850,
        400
      ],
      "credentials": {
        "chatwootApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Search Contact by Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Contact by Email": {
      "main": [
        [
          {
            "node": "Contact Found?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Contact Found?": {
      "main": [
        [
          {
            "node": "Update Contact",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create New Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "saveDataSuccessExecution": "all",
    "saveDataErrorExecution": "all"
  },
  "staticData": null,
  "tags": []
}