{
  "openapi": "3.1.0",
  "info": {
    "title": "ПочтаХаб — предварительный расчёт доставки",
    "version": "1.0.0",
    "description": "Предварительная итоговая цена и срок доставки одной посылки СДЭК по городам, весу и размерам упаковки. ФИО, телефон и точные адреса не нужны. Для каждого варианта отправки и получения нужен отдельный запрос. Расчёт не создаёт заказ, не вызывает курьера и не принимает оплату."
  },
  "servers": [{ "url": "https://pochtahub.ru" }],
  "paths": {
    "/api/tariffs/calculate/": {
      "post": {
        "operationId": "calculateDeliveryQuote",
        "summary": "Получить предварительный тариф СДЭК",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/QuoteInput" },
              "example": {
                "from_city": "Москва",
                "to_city": "Санкт-Петербург",
                "weight": 3,
                "length": 35,
                "width": 30,
                "height": 25,
                "courier_pickup": true,
                "courier_delivery": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Предварительная цена в рублях и срок в днях, если СДЭК его вернул. Интервал забора уточняется отдельно.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/QuoteResult" }
              }
            }
          },
          "400": { "description": "Некорректный JSON или значения полей." },
          "403": { "description": "Запрос из браузера с другого источника не принимается." },
          "411": { "description": "Не указан размер тела запроса." },
          "413": { "description": "Недопустимый размер запроса." },
          "415": { "description": "Неподдерживаемый тип содержимого." },
          "422": { "description": "Город не найден или неоднозначен в справочнике перевозчика." },
          "429": {
            "description": "Превышен лимит запросов. Перед повтором проверьте Retry-After.",
            "headers": {
              "Retry-After": {
                "description": "Пауза перед повтором в секундах, если сервер её указал.",
                "schema": { "type": "integer", "minimum": 0 }
              }
            }
          },
          "503": { "description": "Расчёт временно недоступен." }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "City": {
        "type": "string",
        "minLength": 1,
        "maxLength": 64,
        "pattern": "^[A-Za-zА-Яа-яЁё0-9][A-Za-zА-Яа-яЁё0-9 .-]*$",
        "description": "Название города в России. Укажите город без улицы, дома и контактов."
      },
      "Dimension": {
        "type": "integer",
        "minimum": 1,
        "maximum": 150,
        "description": "Размер упаковки в сантиметрах."
      },
      "QuoteInput": {
        "type": "object",
        "required": ["from_city", "to_city", "weight", "length", "width", "height"],
        "properties": {
          "from_city": { "$ref": "#/components/schemas/City" },
          "to_city": { "$ref": "#/components/schemas/City" },
          "from_city_fias_id": {
            "type": "string",
            "format": "uuid",
            "description": "Идентификатор города отправления по ФИАС, если пользователь выбрал его из подсказок. Помогает различить одноимённые города."
          },
          "to_city_fias_id": {
            "type": "string",
            "format": "uuid",
            "description": "Идентификатор города получения по ФИАС, если пользователь выбрал его из подсказок. Помогает различить одноимённые города."
          },
          "weight": {
            "type": "number",
            "minimum": 0.001,
            "maximum": 30,
            "multipleOf": 0.001,
            "description": "Вес упакованной посылки в килограммах."
          },
          "length": { "$ref": "#/components/schemas/Dimension" },
          "width": { "$ref": "#/components/schemas/Dimension" },
          "height": { "$ref": "#/components/schemas/Dimension" },
          "courier_pickup": {
            "type": "boolean",
            "default": true,
            "description": "Курьерский забор. false означает сдачу посылки в пункте СДЭК."
          },
          "courier_delivery": {
            "type": "boolean",
            "default": true,
            "description": "Курьерская доставка. false означает получение в пункте СДЭК."
          },
          "declared_value": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100000,
            "description": "Объявленная стоимость в рублях для расчёта страхования."
          }
        }
      },
      "QuoteResult": {
        "type": "object",
        "required": ["provider", "options"],
        "properties": {
          "provider": { "const": "cdek" },
          "options": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1,
            "items": { "$ref": "#/components/schemas/QuoteOption" }
          }
        }
      },
      "QuoteOption": {
        "type": "object",
        "required": [
          "company_id", "company_name", "company_code", "tariff_code", "tariff_name",
          "delivery_price", "seller_pickup_service_fee", "price", "currency",
          "delivery_time", "delivery_time_min", "delivery_time_max", "insurance_cost"
        ],
        "properties": {
          "company_id": { "type": "null" },
          "company_name": { "const": "CDEK" },
          "company_code": { "const": "cdek" },
          "tariff_code": { "type": "integer", "enum": [136, 137, 138, 139] },
          "tariff_name": { "type": "string" },
          "delivery_price": { "type": "number", "description": "Стоимость перевозчика в рублях, включая услуги СДЭК, вошедшие в его расчёт." },
          "seller_pickup_service_fee": { "type": "number", "description": "Комиссия ПочтаХаба в рублях. Уже включена в итоговую цену price." },
          "price": { "type": "number", "description": "Предварительная итоговая цена в рублях. Сумма delivery_price и seller_pickup_service_fee." },
          "currency": { "const": "RUB" },
          "delivery_time": { "type": ["integer", "null"], "description": "Ориентир в днях, верхняя граница, если известна." },
          "delivery_time_min": { "type": ["integer", "null"] },
          "delivery_time_max": { "type": ["integer", "null"] },
          "insurance_cost": { "type": ["number", "null"], "description": "Стоимость страхования в рублях, если оно было запрошено. Уже входит в delivery_price." }
        }
      }
    }
  }
}
