{
  "name": "Сделки в CRM через HTTP Request: пачки, повторы, разбор ответа",
  "nodes": [
    {
      "parameters": {
        "content": "## Запрос к API CRM\nОтправляет пачками по 10 с секундной паузой, повторяет упавший запрос до трёх раз и не падает на ошибке: код ответа уходит дальше, и узел «Слить» держит рядом отправленное и ответ.\n\nПосле импорта: адрес метода и токен (Header Auth), свои поля вместо тестовых.",
        "width": 560,
        "height": 220
      },
      "id": "629a39c9-85ad-50f1-ad9e-bc57456a7a56",
      "name": "Заметка c7c4c8",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -280
      ]
    },
    {
      "parameters": {},
      "id": "5c488717-4a52-54d7-a5a7-d10ce04d7a5b",
      "name": "Запуск вручную",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "mode": "raw",
        "jsonOutput": "={\n  \"name\": \"Иван Петров\",\n  \"phone\": \"+79990001122\",\n  \"amount\": 15000,\n  \"source\": \"сайт\"\n}",
        "options": {}
      },
      "id": "0f4a354b-899c-5161-b965-bfcbc154a7d8",
      "name": "Тестовые сделки",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://crm.example.ru/api/v1/deals",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"title\": \"{{ $json.name }}\",\n  \"phone\": \"{{ $json.phone }}\",\n  \"amount\": {{ $json.amount }},\n  \"source\": \"{{ $json.source }}\"\n}",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 10,
              "batchInterval": 1000
            }
          },
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          }
        }
      },
      "id": "327fb9e5-337c-5dae-a643-2f62d0c02cf1",
      "name": "Создать сделку",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        100
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "options": {}
      },
      "id": "8caeee7f-d86c-50bd-a071-87395c330353",
      "name": "Слить",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "578786fe-4c24-53a8-b9c2-3f41abfdf876",
              "leftValue": "={{ $json.statusCode }}",
              "operator": {
                "type": "number",
                "operation": "equals"
              },
              "rightValue": 201
            }
          ],
          "combinator": "and"
        }
      },
      "id": "fa9f74a0-63a5-5015-bb52-b2ded30f9c74",
      "name": "Создалась?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        880,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "g1",
              "name": "deal_id",
              "type": "string",
              "value": "={{ $json.body.id }}"
            },
            {
              "id": "g2",
              "name": "phone",
              "type": "string",
              "value": "={{ $json.phone }}"
            }
          ]
        },
        "options": {}
      },
      "id": "7925b7a0-29b0-5afc-959a-676dd2ba2eab",
      "name": "Готово",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1100,
        -100
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "e1",
              "name": "code",
              "type": "number",
              "value": "={{ $json.statusCode }}"
            },
            {
              "id": "e2",
              "name": "phone",
              "type": "string",
              "value": "={{ $json.phone }}"
            },
            {
              "id": "e3",
              "name": "error",
              "type": "string",
              "value": "={{ JSON.stringify($json.body) }}"
            }
          ]
        },
        "options": {}
      },
      "id": "5876aebf-c2d4-5dbf-a833-c387510a4823",
      "name": "Разобрать ошибку",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1100,
        120
      ]
    }
  ],
  "connections": {
    "Запуск вручную": {
      "main": [
        [
          {
            "node": "Тестовые сделки",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Тестовые сделки": {
      "main": [
        [
          {
            "node": "Создать сделку",
            "type": "main",
            "index": 0
          },
          {
            "node": "Слить",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Слить": {
      "main": [
        [
          {
            "node": "Создалась?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Создалась?": {
      "main": [
        [
          {
            "node": "Готово",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Разобрать ошибку",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Создать сделку": {
      "main": [
        [
          {
            "node": "Слить",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "active": false,
  "meta": {
    "templateCredsSetupCompleted": false,
    "source": "promtbaza.com/voprosy/shablony-n8n"
  }
}