{
 "openapi": "3.1.0",
 "info": {
  "title": "Numline API",
  "version": "1.0",
  "description": "WhatsApp, Telegram, MAX, Авито, ВКонтакте, SMS, боты Telegram и MAX и чат на сайте - в вашей CRM или своей программе: получать сообщения клиентов вебхуками и отвечать. Каналы подключаются в кабинете app.numline.ru (WhatsApp и MAX - по QR-коду, Telegram - кодом из приложения Telegram), API работает с уже подключёнными. Ключ: «Настройки» → «API и вебхуки» в кабинете. Лимиты: 120 запросов в минуту на ключ, 30 отправок в минуту и 1 новый собеседник в минуту с канала. Документация: https://numline.ru/api",
  "contact": {
   "name": "Поддержка Numline",
   "email": "support@numline.ru",
   "url": "https://numline.ru/api"
  }
 },
 "externalDocs": {
  "description": "Документация и примеры",
  "url": "https://numline.ru/api"
 },
 "servers": [
  {
   "url": "https://app.numline.ru/api/v1"
  }
 ],
 "security": [
  {
   "bearer": []
  },
  {
   "apiKey": []
  }
 ],
 "tags": [
  {
   "name": "Ключ"
  },
  {
   "name": "Каналы"
  },
  {
   "name": "Чаты"
  },
  {
   "name": "Сообщения"
  },
  {
   "name": "Окно чатов"
  },
  {
   "name": "Сотрудники"
  },
  {
   "name": "Контакты и сделки"
  }
 ],
 "paths": {
  "/me": {
   "get": {
    "tags": [
     "Ключ"
    ],
    "operationId": "me",
    "summary": "Проверить ключ: компания и имя ключа",
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "company_id": {
           "type": "integer"
          },
          "company": {
           "type": "string"
          },
          "key": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/channels": {
   "get": {
    "tags": [
     "Каналы"
    ],
    "operationId": "list_channels",
    "summary": "Каналы (номера) компании",
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "channels": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Channel"
           }
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/chats": {
   "get": {
    "tags": [
     "Чаты"
    ],
    "operationId": "list_chats",
    "summary": "Чаты по времени последнего сообщения, новые сверху",
    "description": "Синхронизация - updated_after, листание - before = next_before из прошлого ответа.",
    "parameters": [
     {
      "name": "channel_id",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer"
      },
      "description": "Только чаты этого канала"
     },
     {
      "name": "updated_after",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "format": "date-time"
      },
      "description": "Только чаты с сообщениями позже этой даты (ISO 8601 с часовым поясом)"
     },
     {
      "name": "before",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "format": "date-time"
      },
      "description": "Листание: next_before из прошлого ответа"
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 200,
       "default": 50
      },
      "description": "Сколько чатов"
     }
    ],
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "chats": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Chat"
           }
          },
          "has_more": {
           "type": "boolean"
          },
          "next_before": {
           "type": [
            "string",
            "null"
           ],
           "format": "date-time"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/chats/{chat_id}": {
   "get": {
    "tags": [
     "Чаты"
    ],
    "operationId": "get_chat",
    "summary": "Один чат",
    "parameters": [
     {
      "name": "chat_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "id чата"
     }
    ],
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Chat"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    }
   }
  },
  "/chats/{chat_id}/messages": {
   "get": {
    "tags": [
     "Сообщения"
    ],
    "operationId": "list_messages",
    "summary": "Сообщения чата: по умолчанию последние, новые сверху",
    "parameters": [
     {
      "name": "chat_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "id чата"
     },
     {
      "name": "before_id",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer"
      },
      "description": "Сообщения старше этого id"
     },
     {
      "name": "after_id",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer"
      },
      "description": "Сообщения новее этого id, по порядку - для синхронизации"
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 200,
       "default": 50
      },
      "description": "Сколько сообщений"
     }
    ],
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "messages": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Message"
           }
          },
          "has_more": {
           "type": "boolean"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    }
   }
  },
  "/messages/{msg_id}": {
   "get": {
    "tags": [
     "Сообщения"
    ],
    "operationId": "get_message",
    "summary": "Одно сообщение вместе с чатом",
    "parameters": [
     {
      "name": "msg_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "id сообщения"
     }
    ],
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Message"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    }
   }
  },
  "/messages": {
   "post": {
    "tags": [
     "Сообщения"
    ],
    "operationId": "send_message",
    "summary": "Отправить текст и (или) файл",
    "description": "В существующий чат - chat_id; новому собеседнику - channel_id и phone (не больше одного нового собеседника в минуту с канала; Авито, ВКонтакте, Instagram, боты и чат на сайте - только ответ в существующий чат). Окончательный статус приходит вебхуком message.status. Не используйте для рассылок: мессенджеры блокируют номера за массовые сообщения незнакомым людям.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/SendMessage"
       },
       "examples": {
        "chat": {
         "summary": "В существующий чат",
         "value": {
          "chat_id": 345,
          "text": "Добрый день! Заказ готов"
         }
        },
        "phone": {
         "summary": "По номеру телефона",
         "value": {
          "channel_id": 12,
          "phone": "79990001122",
          "text": "Добрый день!",
          "author": "Мария Петрова"
         }
        }
       }
      },
      "multipart/form-data": {
       "schema": {
        "allOf": [
         {
          "$ref": "#/components/schemas/SendMessage"
         },
         {
          "type": "object",
          "properties": {
           "file": {
            "type": "string",
            "format": "binary",
            "description": "До 64 МБ"
           }
          }
         }
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Сообщение создано",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Message"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "422": {
      "description": "Сейчас отправить нельзя: канал не подключён, подписка не оплачена, контакт заблокирован",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "502": {
      "description": "Мессенджер не принял сообщение (status = failed, причина в error)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Message"
        }
       }
      }
     }
    }
   }
  },
  "/iframe": {
   "post": {
    "tags": [
     "Окно чатов"
    ],
    "operationId": "iframe_link",
    "summary": "Одноразовая ссылка (2 минуты) на «Диалоги» Numline для iframe в вашей CRM",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "parent"
        ],
        "properties": {
         "parent": {
          "type": "string",
          "description": "https-адрес сайта CRM, где откроется окно"
         },
         "user": {
          "type": "object",
          "properties": {
           "id": {
            "type": "string"
           },
           "name": {
            "type": "string"
           }
          }
         },
         "scope": {
          "type": "string",
          "enum": [
           "global",
           "card"
          ],
          "default": "global"
         },
         "phone": {
          "type": "string",
          "description": "Для scope = card: телефон клиента, 11 цифр"
         }
        }
       },
       "example": {
        "parent": "https://crm.example.ru",
        "user": {
         "id": "17",
         "name": "Мария Петрова"
        },
        "scope": "global"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "url": {
           "type": "string"
          },
          "expires_in": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    }
   }
  },
  "/unanswered": {
   "get": {
    "tags": [
     "Окно чатов"
    ],
    "operationId": "unanswered",
    "summary": "Чаты, которые ждут ответа (для счётчика в CRM)",
    "parameters": [
     {
      "name": "channel_id",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer"
      },
      "description": "Только этот канал"
     },
     {
      "name": "phone",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Только этот клиент, 11 цифр"
     },
     {
      "name": "user_id",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Только чаты, которые видит этот сотрудник из /users"
     }
    ],
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "count": {
           "type": "integer"
          },
          "chat_ids": {
           "type": "array",
           "items": {
            "type": "integer"
           }
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/user-roles": {
   "get": {
    "tags": [
     "Сотрудники"
    ],
    "operationId": "list_user_roles",
    "summary": "Роли сотрудников на каналах",
    "parameters": [
     {
      "name": "user_id",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Только этот сотрудник"
     }
    ],
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/UserRole"
           }
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "patch": {
    "tags": [
     "Сотрудники"
    ],
    "operationId": "set_user_roles",
    "summary": "Назначить роли (до 100 за запрос)",
    "description": "Можно и методом POST.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "array",
        "items": {
         "$ref": "#/components/schemas/UserRole"
        },
        "maxItems": 100
       },
       "example": [
        {
         "user_id": "17",
         "channel_id": 12,
         "role": "seller",
         "allow_new_clients": true
        }
       ]
      }
     }
    },
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "count": {
           "type": "integer",
           "description": "Сколько записей сохранено"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/users": {
   "get": {
    "tags": [
     "Сотрудники"
    ],
    "operationId": "list_users",
    "summary": "Сотрудники CRM: список",
    "parameters": [
     {
      "name": "offset",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 0,
       "default": 0
      },
      "description": "Сколько записей пропустить"
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 100
      },
      "description": "Сколько записей вернуть"
     }
    ],
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "count",
          "data"
         ],
         "properties": {
          "count": {
           "type": "integer",
           "description": "Всего записей"
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/User"
           }
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Сотрудники"
    ],
    "operationId": "upsert_users",
    "summary": "Сотрудники CRM: добавить или обновить (до 100 за запрос)",
    "description": "Тело - массив. Запись с уже известным id обновляется.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "array",
        "items": {
         "$ref": "#/components/schemas/User"
        },
        "maxItems": 100
       },
       "example": [
        {
         "id": "17",
         "name": "Мария Петрова",
         "phone": "79990001122"
        }
       ]
      }
     }
    },
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "count": {
           "type": "integer",
           "description": "Сколько записей сохранено"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/users/{id}": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     },
     "description": "id в вашей CRM (user)"
    }
   ],
   "get": {
    "tags": [
     "Сотрудники"
    ],
    "operationId": "get_user",
    "summary": "Сотрудники CRM: одна запись",
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/User"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    }
   },
   "delete": {
    "tags": [
     "Сотрудники"
    ],
    "operationId": "delete_user",
    "summary": "Сотрудники CRM: удалить",
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "count": {
           "type": "integer",
           "description": "Сколько записей сохранено"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    }
   }
  },
  "/users/bulk_delete": {
   "patch": {
    "tags": [
     "Сотрудники"
    ],
    "operationId": "bulk_delete_users",
    "summary": "Сотрудники CRM: удалить несколько (до 100)",
    "description": "Можно и методом POST.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "oneOf": [
         {
          "type": "array",
          "items": {
           "type": "string"
          },
          "maxItems": 100
         },
         {
          "type": "object",
          "properties": {
           "ids": {
            "type": "array",
            "items": {
             "type": "string"
            },
            "maxItems": 100
           }
          }
         }
        ]
       },
       "example": [
        "17",
        "18"
       ]
      }
     }
    },
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "not_found": {
           "type": "array",
           "items": {
            "type": "string"
           }
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/contacts": {
   "get": {
    "tags": [
     "Контакты и сделки"
    ],
    "operationId": "list_contacts",
    "summary": "Контакты: список",
    "parameters": [
     {
      "name": "offset",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 0,
       "default": 0
      },
      "description": "Сколько записей пропустить"
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 100
      },
      "description": "Сколько записей вернуть"
     }
    ],
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "count",
          "data"
         ],
         "properties": {
          "count": {
           "type": "integer",
           "description": "Всего записей"
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Contact"
           }
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Контакты и сделки"
    ],
    "operationId": "upsert_contacts",
    "summary": "Контакты: добавить или обновить (до 100 за запрос)",
    "description": "Тело - массив. Запись с уже известным id обновляется.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "array",
        "items": {
         "$ref": "#/components/schemas/Contact"
        },
        "maxItems": 100
       },
       "example": [
        {
         "id": "c-501",
         "name": "Иван Соколов",
         "responsibleUserId": "17",
         "uri": "https://crm.example.ru/contacts/501",
         "contactData": [
          {
           "chatType": "whatsapp",
           "chatId": "79991234567"
          }
         ]
        }
       ]
      }
     }
    },
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "count": {
           "type": "integer",
           "description": "Сколько записей сохранено"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/contacts/{id}": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     },
     "description": "id в вашей CRM (contact)"
    }
   ],
   "get": {
    "tags": [
     "Контакты и сделки"
    ],
    "operationId": "get_contact",
    "summary": "Контакты: одна запись",
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Contact"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    }
   },
   "delete": {
    "tags": [
     "Контакты и сделки"
    ],
    "operationId": "delete_contact",
    "summary": "Контакты: удалить",
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "count": {
           "type": "integer",
           "description": "Сколько записей сохранено"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    }
   }
  },
  "/contacts/bulk_delete": {
   "patch": {
    "tags": [
     "Контакты и сделки"
    ],
    "operationId": "bulk_delete_contacts",
    "summary": "Контакты: удалить несколько (до 100)",
    "description": "Можно и методом POST.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "oneOf": [
         {
          "type": "array",
          "items": {
           "type": "string"
          },
          "maxItems": 100
         },
         {
          "type": "object",
          "properties": {
           "ids": {
            "type": "array",
            "items": {
             "type": "string"
            },
            "maxItems": 100
           }
          }
         }
        ]
       },
       "example": [
        "17",
        "18"
       ]
      }
     }
    },
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "not_found": {
           "type": "array",
           "items": {
            "type": "string"
           }
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/deals": {
   "get": {
    "tags": [
     "Контакты и сделки"
    ],
    "operationId": "list_deals",
    "summary": "Сделки: список",
    "parameters": [
     {
      "name": "offset",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 0,
       "default": 0
      },
      "description": "Сколько записей пропустить"
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 100
      },
      "description": "Сколько записей вернуть"
     }
    ],
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "count",
          "data"
         ],
         "properties": {
          "count": {
           "type": "integer",
           "description": "Всего записей"
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Deal"
           }
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Контакты и сделки"
    ],
    "operationId": "upsert_deals",
    "summary": "Сделки: добавить или обновить (до 100 за запрос)",
    "description": "Тело - массив. Запись с уже известным id обновляется.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "array",
        "items": {
         "$ref": "#/components/schemas/Deal"
        },
        "maxItems": 100
       },
       "example": [
        {
         "id": "d-77",
         "name": "Ипотека",
         "responsibleUserId": "17",
         "closed": false,
         "contacts": [
          "c-501"
         ]
        }
       ]
      }
     }
    },
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "count": {
           "type": "integer",
           "description": "Сколько записей сохранено"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/deals/{id}": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     },
     "description": "id в вашей CRM (deal)"
    }
   ],
   "get": {
    "tags": [
     "Контакты и сделки"
    ],
    "operationId": "get_deal",
    "summary": "Сделки: одна запись",
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Deal"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    }
   },
   "delete": {
    "tags": [
     "Контакты и сделки"
    ],
    "operationId": "delete_deal",
    "summary": "Сделки: удалить",
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "count": {
           "type": "integer",
           "description": "Сколько записей сохранено"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    }
   }
  },
  "/deals/bulk_delete": {
   "patch": {
    "tags": [
     "Контакты и сделки"
    ],
    "operationId": "bulk_delete_deals",
    "summary": "Сделки: удалить несколько (до 100)",
    "description": "Можно и методом POST.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "oneOf": [
         {
          "type": "array",
          "items": {
           "type": "string"
          },
          "maxItems": 100
         },
         {
          "type": "object",
          "properties": {
           "ids": {
            "type": "array",
            "items": {
             "type": "string"
            },
            "maxItems": 100
           }
          }
         }
        ]
       },
       "example": [
        "17",
        "18"
       ]
      }
     }
    },
    "responses": {
     "200": {
      "description": "Успешно",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "not_found": {
           "type": "array",
           "items": {
            "type": "string"
           }
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  }
 },
 "webhooks": {
  "event": {
   "post": {
    "summary": "События Numline на ваш https-адрес",
    "description": "Адрес добавляется в «Настройки» → «API и вебхуки» (до 3 адресов). Заголовки: X-Numline-Event, X-Numline-Delivery (id события), X-Numline-Attempt, X-Numline-Signature = «sha256=» + HMAC-SHA256 сырого тела с секретом вебхука (whsec_...). Ответьте 2xx за 10 секунд, иначе повтор через 1, 5, 30 мин, 2, 6, 12 ч.",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/WebhookEvent"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Принято"
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "bearer": {
    "type": "http",
    "scheme": "bearer",
    "description": "Authorization: Bearer nl_..."
   },
   "apiKey": {
    "type": "apiKey",
    "in": "header",
    "name": "X-Api-Key"
   }
  },
  "schemas": {
   "Error": {
    "type": "object",
    "required": [
     "code",
     "error"
    ],
    "properties": {
     "code": {
      "type": "string",
      "description": "Код ошибки для программы: unauthorized, not_found, rate_limited, not_sent..."
     },
     "error": {
      "type": "string",
      "description": "Текст ошибки по-русски"
     }
    }
   },
   "Channel": {
    "type": "object",
    "description": "Канал компании: мессенджер на номере, аккаунт Авито, сообщество ВКонтакте, бот, чат на сайте",
    "properties": {
     "id": {
      "type": "integer"
     },
     "kind": {
      "type": "string",
      "enum": [
       "whatsapp",
       "telegram",
       "max",
       "sms",
       "avito",
       "vk",
       "tgbot",
       "maxbot",
       "instagram",
       "site"
      ]
     },
     "phone": {
      "type": "string",
      "description": "Номер, 11 цифр (у каналов без номера - пусто)"
     },
     "title": {
      "type": "string"
     },
     "state": {
      "type": "string",
      "description": "connected - работает; qr, logged_out, disconnected, stopped, error - не работает, нужно подключить в кабинете"
     },
     "enabled": {
      "type": "boolean"
     },
     "private": {
      "type": "boolean",
      "description": "Личный номер сотрудника: видны только одобренные им собеседники"
     }
    }
   },
   "Chat": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer"
     },
     "channel_id": {
      "type": "integer"
     },
     "kind": {
      "type": "string",
      "enum": [
       "whatsapp",
       "telegram",
       "max",
       "sms",
       "avito",
       "vk",
       "tgbot",
       "maxbot",
       "instagram",
       "site"
      ]
     },
     "phone": {
      "type": "string",
      "description": "Телефон клиента, 11 цифр, если известен"
     },
     "peer_id": {
      "type": "string",
      "description": "id собеседника в мессенджере"
     },
     "name": {
      "type": "string"
     },
     "username": {
      "type": "string"
     },
     "is_group": {
      "type": "boolean"
     },
     "closed": {
      "type": "boolean"
     },
     "assignee_id": {
      "type": [
       "integer",
       "null"
      ]
     },
     "last_message_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     }
    }
   },
   "Message": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer"
     },
     "chat_id": {
      "type": "integer"
     },
     "direction": {
      "type": "string",
      "enum": [
       "in",
       "out"
      ],
      "description": "in - от клиента, out - клиенту"
     },
     "origin": {
      "type": "string",
      "description": "client - клиент; panel - из Numline или через API; amo - из CRM; phone - с самого телефона; auto - автоответ"
     },
     "type": {
      "type": "string",
      "enum": [
       "text",
       "picture",
       "video",
       "file",
       "voice",
       "audio",
       "sticker"
      ]
     },
     "text": {
      "type": "string"
     },
     "status": {
      "type": "string",
      "description": "Исходящее: sending, new, sent, delivered, read, failed"
     },
     "error": {
      "type": "string",
      "description": "Причина, если status = failed"
     },
     "file_name": {
      "type": "string"
     },
     "mime": {
      "type": "string"
     },
     "file_url": {
      "type": "string",
      "description": "Временная ссылка на файл: скачайте, если он нужен надолго"
     },
     "transcript": {
      "type": "string",
      "description": "Расшифровка голосового"
     },
     "author": {
      "type": "string",
      "description": "Кто из сотрудников отправил"
     },
     "sender_name": {
      "type": "string",
      "description": "Участник группового чата"
     },
     "sender_phone": {
      "type": "string"
     },
     "ts": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "chat": {
      "$ref": "#/components/schemas/Chat",
      "description": "Есть в ответе на отправку, в GET /messages/{id} и в вебхуках"
     }
    }
   },
   "SendMessage": {
    "type": "object",
    "description": "Нужен chat_id или пара channel_id + phone; нужен text, file_url или файл (multipart)",
    "properties": {
     "chat_id": {
      "type": "integer",
      "description": "Существующий чат"
     },
     "channel_id": {
      "type": "integer",
      "description": "С какого канала писать новому собеседнику"
     },
     "phone": {
      "type": "string",
      "description": "Номер получателя, 11 цифр: 79991234567"
     },
     "text": {
      "type": "string",
      "maxLength": 4000
     },
     "file_url": {
      "type": "string",
      "format": "uri",
      "description": "https-ссылка на файл на публичном сервере"
     },
     "file_name": {
      "type": "string"
     },
     "author": {
      "type": "string",
      "maxLength": 100,
      "description": "Имя сотрудника вашей CRM: будет в «Диалогах» и в CRM вместо имени ключа"
     }
    }
   },
   "User": {
    "type": "object",
    "required": [
     "id",
     "name"
    ],
    "properties": {
     "id": {
      "type": "string",
      "maxLength": 64,
      "description": "id сотрудника в вашей CRM"
     },
     "name": {
      "type": "string",
      "maxLength": 150
     },
     "phone": {
      "type": "string"
     }
    }
   },
   "UserRole": {
    "type": "object",
    "required": [
     "user_id",
     "channel_id",
     "role"
    ],
    "properties": {
     "user_id": {
      "type": "string"
     },
     "channel_id": {
      "type": "integer"
     },
     "role": {
      "type": "string",
      "enum": [
       "seller",
       "manager",
       "auditor",
       "none"
      ],
      "description": "seller - только свои клиенты; manager - все клиенты номера; auditor - все, только чтение; none - убрать доступ"
     },
     "allow_new_clients": {
      "type": "boolean",
      "description": "seller видит и ещё ничьих клиентов"
     }
    }
   },
   "Contact": {
    "type": "object",
    "required": [
     "id"
    ],
    "properties": {
     "id": {
      "type": "string",
      "maxLength": 64
     },
     "name": {
      "type": "string"
     },
     "responsibleUserId": {
      "type": "string"
     },
     "uri": {
      "type": "string",
      "description": "Ссылка на карточку в CRM (http/https)"
     },
     "contactData": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "chatType": {
         "type": "string",
         "enum": [
          "whatsapp",
          "telegram",
          "max",
          "sms",
          "vk",
          "avito"
         ]
        },
        "chatId": {
         "type": "string",
         "description": "whatsapp, max, sms - телефон; telegram - id, username или телефон с «+»; vk, avito - id собеседника"
        },
        "phone": {
         "type": "string"
        }
       }
      }
     }
    }
   },
   "Deal": {
    "type": "object",
    "required": [
     "id"
    ],
    "properties": {
     "id": {
      "type": "string",
      "maxLength": 64
     },
     "name": {
      "type": "string"
     },
     "responsibleUserId": {
      "type": "string"
     },
     "uri": {
      "type": "string"
     },
     "closed": {
      "type": "boolean"
     },
     "contacts": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "maxItems": 10,
      "description": "id контактов из /contacts"
     }
    }
   },
   "WebhookEvent": {
    "type": "object",
    "required": [
     "event",
     "id",
     "ts",
     "data"
    ],
    "properties": {
     "event": {
      "type": "string",
      "enum": [
       "message.incoming",
       "message.outgoing",
       "message.status",
       "channel.state",
       "webhook.test"
      ]
     },
     "id": {
      "type": "string",
      "description": "id события: одно событие может прийти дважды, сверяйте"
     },
     "ts": {
      "type": "string",
      "format": "date-time"
     },
     "company_id": {
      "type": "integer"
     },
     "data": {
      "type": "object",
      "description": "message.* - сообщение с полем chat; message.status - {id, chat_id, status, error}; channel.state - канал и previous, detail"
     }
    }
   }
  },
  "responses": {
   "BadRequest": {
    "description": "Неверные параметры",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "Unauthorized": {
    "description": "Нет ключа, ключ неверный или отозван",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "Forbidden": {
    "description": "Нет доступа: личный номер сотрудника, закрытый доступ компании",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "NotFound": {
    "description": "Не найдено",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "RateLimited": {
    "description": "Превышен лимит запросов",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   }
  }
 }
}