{
  "name": "Tech My PME — Sync Ksaar to CRM",
  "nodes": [
    {
      "id": "5079b534-2de9-4438-f3ae-063b6c651f26",
      "name": "Webhook Ksaar",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        240,
        300
      ],
      "parameters": {
        "path": "ksaar-sync",
        "httpMethod": "POST",
        "responseMode": "onReceived"
      }
    },
    {
      "id": "bedce527-2792-4c98-ef7e-7743eba90c96",
      "name": "Transform Data",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        300
      ],
      "parameters": {
        "language": "javaScript",
        "jsCode": "const contact = {\n  name: $input.body.contact_name,\n  email: $input.body.contact_email,\n  phone: $input.body.contact_phone,\n  company: $input.body.company_name,\n  source: 'ksaar'\n};\nreturn [{ json: contact }];"
      }
    },
    {
      "id": "2836cf76-1018-4e60-526e-1a928b03fab4",
      "name": "Check Data Validity",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        720,
        300
      ],
      "parameters": {
        "conditions": {
          "options": [
            {
              "condition": "ifEmpty",
              "value1": "={{ $json.email }}",
              "operator": {
                "name": "isEmpty",
                "type": "string"
              }
            }
          ]
        }
      }
    },
    {
      "id": "ee6d295c-baff-41fb-57a8-346514bf8c41",
      "name": "Push to CRM",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        960,
        200
      ],
      "parameters": {
        "url": "={{ $env.CRM_API_URL }}/contacts",
        "method": "POST",
        "headers": {
          "Authorization": "Bearer {{ $env.CRM_API_KEY }}",
          "Content-Type": "application/json"
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "={{ $json.name }}"
            },
            {
              "name": "email",
              "value": "={{ $json.email }}"
            },
            {
              "name": "phone",
              "value": "={{ $json.phone }}"
            },
            {
              "name": "company",
              "value": "={{ $json.company }}"
            }
          ]
        }
      }
    },
    {
      "id": "7acf2f6e-d21f-41aa-c743-b125d45a9eb4",
      "name": "Log Error",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        960,
        400
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "error_message",
              "value": "Email is required for CRM sync"
            }
          ]
        }
      }
    }
  ],
  "connections": {
    "Webhook Ksaar": {
      "main": [
        [
          {
            "node": "Transform Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transform Data": {
      "main": [
        [
          {
            "node": "Check Data Validity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Data Validity": {
      "main": [
        [
          {
            "node": "Push to CRM",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "versionId": "86ee2629-a1d1-4fab-1168-a006227e6bfb"
}