{
  "name": "Nodbot - 1C HTTP exchange with idempotency",
  "nodes": [
    {
      "parameters": {
        "path": "onec-http-exchange",
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "id": "4ce8e47f-33a7-4351-b535-0bd73b979c4d",
      "name": "1C Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const src = $json.body ?? $json;\nconst eventType = String(src.event_type ?? '').trim();\nconst externalId = String(src.external_id ?? '').trim();\nif (!eventType) throw new Error('Missing event_type from 1C');\nif (!externalId) throw new Error('Missing external_id from 1C');\n\nconst items = Array.isArray(src.items) ? src.items : [];\nif (items.length === 0) throw new Error('Order has no items');\n\nconst normalizedItems = items.map((item, index) => {\n  const quantity = Number(item.quantity ?? 0);\n  const price = Number(item.price ?? 0);\n  if (quantity <= 0) throw new Error(`Invalid quantity at line ${index + 1}`);\n  return {\n    sku: String(item.sku ?? '').trim(),\n    name: String(item.name ?? '').trim(),\n    quantity,\n    price,\n    amount: Number((quantity * price).toFixed(2)),\n    vat: String(item.vat ?? 'none')\n  };\n});\n\nconst total = normalizedItems.reduce((sum, item) => sum + item.amount, 0);\nconst idempotencyKey = `1c:${eventType}:${externalId}`;\n\nreturn [{\n  json: {\n    event_type: eventType,\n    external_id: externalId,\n    idempotency_key: idempotencyKey,\n    order_number: String(src.number ?? externalId),\n    customer: src.customer ?? {},\n    items: normalizedItems,\n    total_calculated: Number(total.toFixed(2)),\n    total_declared: Number(src.total ?? total),\n    status: String(src.status ?? 'new'),\n    received_at: new Date().toISOString()\n  }\n}];"
      },
      "id": "f15df5d2-873e-404b-b234-3e83fd7ca327",
      "name": "Normalize 1C order",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        260
      ]
    },
    {
      "parameters": {},
      "id": "7b25332f-4a0b-48ab-87a2-b10c40999044",
      "name": "Check idempotency",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        560,
        260
      ]
    },
    {
      "parameters": {},
      "id": "99804494-a9f6-4d56-9a94-8e93320ae35c",
      "name": "Upsert CRM or API",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        840,
        260
      ]
    },
    {
      "parameters": {},
      "id": "1233215e-7183-4c3b-a6d9-90772bbf11a7",
      "name": "Write exchange log",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        1120,
        260
      ]
    },
    {
      "parameters": {},
      "id": "3a5c4f82-829a-44e7-9795-0188c3a3b475",
      "name": "Respond to 1C",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 2,
      "position": [
        1400,
        260
      ]
    }
  ],
  "connections": {
    "1C Webhook": {
      "main": [
        [
          {
            "node": "Normalize 1C order",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize 1C order": {
      "main": [
        [
          {
            "node": "Check idempotency",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check idempotency": {
      "main": [
        [
          {
            "node": "Upsert CRM or API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert CRM or API": {
      "main": [
        [
          {
            "node": "Write exchange log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write exchange log": {
      "main": [
        [
          {
            "node": "Respond to 1C",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "nodbot",
    "production",
    "template"
  ],
  "triggerCount": 1,
  "updatedAt": "2026-05-30T00:00:00.000Z",
  "versionId": "95208196-d9b5-4e4c-b63c-d609e0bc5cde",
  "meta": {
    "templateCredsSetupCompleted": false
  }
}