{
    "openapi": "3.0.3",
    "info": {
        "title": "ShipPickup API (lite)",
        "version": "v1",
        "description": "Key operations of the ShipPickup shipping API: rates, buy and cancel labels, shipments, tracking, balance. Authentication: Authorization: Bearer <API key>. Full specification: /openapi.json."
    },
    "servers": [
        {
            "url": "https://api.shippickup.com/v1"
        }
    ],
    "security": [
        {
            "bearerAuth": []
        }
    ],
    "paths": {
        "/balance": {
            "get": {
                "operationId": "get_balance",
                "summary": "Баланс",
                "description": "Нужно право `balance:read`.",
                "responses": {
                    "200": {
                        "description": "Текущий баланс",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/BalanceResponse"
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/rates": {
            "post": {
                "operationId": "get_shipping_rates",
                "summary": "Тарифы",
                "description": "Нужно право `rates:read`. Возвращает предложения для маршрута и посылки, отсортированные по цене. Цена `price_cents` это то, что заплатит клиент. Для создания лейбла передаётся `rate_id` (действует 15 минут, привязан к цене и сервису, подделать нельзя).",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/RatesRequest"
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Список тарифов",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/RatesResponse"
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/shipments": {
            "post": {
                "operationId": "create_shipment",
                "summary": "Купить лейбл",
                "description": "Нужно право `labels:create`, только боевой ключ (тестовый получит 403 `test_key_cannot_buy`). Обязателен заголовок `Idempotency-Key` (16–64 символа `A-Za-z0-9_-`): повтор запроса с тем же ключом возвращает тот же заказ и не списывает деньги второй раз. `rate_…",
                "parameters": [
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/ShipmentCreateRequest"
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Заказ создан (200, если это повтор с тем же Idempotency-Key)",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/ShipmentResponse"
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "get": {
                "operationId": "list_shipments",
                "summary": "Список заказов",
                "description": "Право `labels:read`. Новые первыми. Фильтры сочетаются: `status`, `carrier`, `created_from` / `created_to` (дата или время ISO 8601, UTC), `updated_since` (изменённые с указанного времени), `tracking_number`, `reference` (ваш номер заказа, переданный при созд…",
                "parameters": [
                    {
                        "name": "status",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        },
                        "description": "Например label_ready, in_transit, delivered, cancelled"
                    },
                    {
                        "name": "carrier",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        },
                        "description": "Перевозчик, как в поле carrier заказа (без учёта регистра)"
                    },
                    {
                        "name": "created_from",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "format": "date-time"
                        }
                    },
                    {
                        "name": "created_to",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "format": "date-time"
                        }
                    },
                    {
                        "name": "updated_since",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "format": "date-time"
                        }
                    },
                    {
                        "name": "tracking_number",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "reference",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "maxLength": 64
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 100,
                            "default": 20
                        }
                    },
                    {
                        "name": "offset",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "minimum": 0,
                            "default": 0
                        }
                    },
                    {
                        "name": "cursor",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Список заказов",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/ShipmentListResponse"
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/shipments/{id}": {
            "get": {
                "operationId": "get_shipment",
                "summary": "Заказ",
                "description": "Право `labels:read`. `id` это номер заказа или трек-номер.",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Заказ",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/ShipmentResponse"
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/shipments/{id}/cancel": {
            "post": {
                "operationId": "cancel_shipment",
                "summary": "Отменить заказ",
                "description": "Право `labels:cancel`. Отменить можно заказ, пока посылка не передана перевозчику. Повторная отмена безопасна (идемпотентна): ответ 200 с `meta.already_cancelled = true`, деньги второй раз не возвращаются. Возврат: деньги за лейбл возвращаются на баланс через…",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "reason": {
                                        "type": "string",
                                        "maxLength": 255
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Заказ с новым статусом; `meta.refund_cents` сколько возвращено",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/ShipmentResponse"
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/shipments/{id}/tracking": {
            "get": {
                "operationId": "get_tracking",
                "summary": "Отслеживание",
                "description": "Право `tracking:read`. Заказ и события пути, новые первыми.",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Заказ с полем events",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/ShipmentTrackingResponse"
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer"
            }
        },
        "schemas": {
            "BalanceResponse": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "currency": {
                                "type": "string",
                                "example": "USD"
                            },
                            "balance_cents": {
                                "type": "integer",
                                "example": 124860
                            },
                            "balance": {
                                "type": "string",
                                "example": "1248.60"
                            }
                        }
                    }
                }
            },
            "Error": {
                "type": "object",
                "required": [
                    "error"
                ],
                "properties": {
                    "error": {
                        "type": "object",
                        "required": [
                            "code",
                            "message"
                        ],
                        "properties": {
                            "code": {
                                "type": "string",
                                "example": "validation_failed"
                            },
                            "message": {
                                "type": "string"
                            },
                            "details": {
                                "type": "object",
                                "additionalProperties": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                }
            },
            "RatesRequest": {
                "type": "object",
                "required": [
                    "from",
                    "to",
                    "parcel"
                ],
                "properties": {
                    "from": {
                        "$ref": "#/components/schemas/Address"
                    },
                    "to": {
                        "$ref": "#/components/schemas/Address"
                    },
                    "parcel": {
                        "$ref": "#/components/schemas/Parcel"
                    },
                    "declared_value_cents": {
                        "type": "integer",
                        "minimum": 0
                    }
                }
            },
            "RatesResponse": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "array",
                        "items": {
                            "$ref": "#/components/schemas/Rate"
                        }
                    },
                    "meta": {
                        "type": "object",
                        "properties": {
                            "count": {
                                "type": "integer"
                            },
                            "partial": {
                                "type": "boolean",
                                "description": "true, если часть тарифов недоступна"
                            }
                        }
                    }
                }
            },
            "ShipmentCreateRequest": {
                "type": "object",
                "required": [
                    "rate_id",
                    "from",
                    "to",
                    "parcel"
                ],
                "properties": {
                    "rate_id": {
                        "type": "string"
                    },
                    "from": {
                        "$ref": "#/components/schemas/ShipmentAddress"
                    },
                    "to": {
                        "$ref": "#/components/schemas/ShipmentAddress"
                    },
                    "parcel": {
                        "$ref": "#/components/schemas/Parcel"
                    },
                    "items": {
                        "type": "array",
                        "items": {
                            "$ref": "#/components/schemas/ShipmentItem"
                        },
                        "description": "Для международной отправки обязательно"
                    },
                    "declared_value_cents": {
                        "type": "integer",
                        "description": "По умолчанию сумма содержимого"
                    },
                    "services": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        },
                        "description": "Коды дополнительных услуг"
                    },
                    "reference": {
                        "type": "string",
                        "maxLength": 64,
                        "description": "Ваш номер заказа (необязательно). Уникален в пределах аккаунта: повтор с другим Idempotency-Key даёт 409"
                    }
                }
            },
            "ShipmentResponse": {
                "type": "object",
                "properties": {
                    "data": {
                        "$ref": "#/components/schemas/Shipment"
                    },
                    "meta": {
                        "type": "object"
                    }
                }
            },
            "ShipmentListResponse": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "array",
                        "items": {
                            "$ref": "#/components/schemas/Shipment"
                        }
                    },
                    "meta": {
                        "type": "object",
                        "properties": {
                            "total": {
                                "type": "integer"
                            },
                            "limit": {
                                "type": "integer"
                            },
                            "offset": {
                                "type": "integer"
                            }
                        }
                    }
                }
            },
            "ShipmentTrackingResponse": {
                "type": "object",
                "properties": {
                    "data": {
                        "allOf": [
                            {
                                "$ref": "#/components/schemas/Shipment"
                            },
                            {
                                "type": "object",
                                "properties": {
                                    "events": {
                                        "type": "array",
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "time": {
                                                    "type": "string",
                                                    "format": "date-time"
                                                },
                                                "status": {
                                                    "type": "string",
                                                    "nullable": true
                                                },
                                                "message": {
                                                    "type": "string"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        ]
                    }
                }
            },
            "Address": {
                "type": "object",
                "required": [
                    "country",
                    "postal_code"
                ],
                "properties": {
                    "country": {
                        "type": "string",
                        "description": "ISO 3166-1 alpha-2",
                        "example": "DE"
                    },
                    "postal_code": {
                        "type": "string",
                        "example": "10117"
                    },
                    "city": {
                        "type": "string"
                    },
                    "line1": {
                        "type": "string"
                    },
                    "state": {
                        "type": "string"
                    }
                }
            },
            "Parcel": {
                "type": "object",
                "required": [
                    "weight_g",
                    "length_mm",
                    "width_mm",
                    "height_mm"
                ],
                "properties": {
                    "weight_g": {
                        "type": "integer",
                        "minimum": 1,
                        "description": "Вес в граммах",
                        "example": 2400
                    },
                    "length_mm": {
                        "type": "integer",
                        "minimum": 1,
                        "example": 300
                    },
                    "width_mm": {
                        "type": "integer",
                        "minimum": 1,
                        "example": 200
                    },
                    "height_mm": {
                        "type": "integer",
                        "minimum": 1,
                        "example": 150
                    }
                }
            },
            "Rate": {
                "type": "object",
                "properties": {
                    "rate_id": {
                        "type": "string",
                        "description": "Непрозрачный идентификатор тарифа, действует 15 минут"
                    },
                    "carrier": {
                        "type": "string",
                        "example": "UPS"
                    },
                    "service": {
                        "type": "string",
                        "example": "Express Saver"
                    },
                    "price_cents": {
                        "type": "integer",
                        "example": 4120
                    },
                    "price": {
                        "type": "string",
                        "example": "41.20"
                    },
                    "currency": {
                        "type": "string",
                        "example": "USD"
                    },
                    "eta_days_min": {
                        "type": "integer",
                        "nullable": true
                    },
                    "eta_days_max": {
                        "type": "integer",
                        "nullable": true
                    },
                    "pickup_supported": {
                        "type": "boolean"
                    },
                    "chargeable_weight_g": {
                        "type": "integer",
                        "description": "Вес, по которому считается тариф (больший из фактического и объёмного)"
                    }
                }
            },
            "ShipmentAddress": {
                "type": "object",
                "required": [
                    "name",
                    "line1",
                    "city",
                    "country",
                    "postal_code"
                ],
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "company": {
                        "type": "string"
                    },
                    "line1": {
                        "type": "string"
                    },
                    "line2": {
                        "type": "string"
                    },
                    "city": {
                        "type": "string"
                    },
                    "state": {
                        "type": "string"
                    },
                    "postal_code": {
                        "type": "string"
                    },
                    "country": {
                        "type": "string",
                        "example": "DE"
                    },
                    "phone": {
                        "type": "string"
                    },
                    "email": {
                        "type": "string"
                    }
                }
            },
            "ShipmentItem": {
                "type": "object",
                "required": [
                    "description",
                    "quantity",
                    "unit_value_cents"
                ],
                "properties": {
                    "description": {
                        "type": "string",
                        "example": "T-shirts"
                    },
                    "quantity": {
                        "type": "integer",
                        "minimum": 1
                    },
                    "unit_value_cents": {
                        "type": "integer",
                        "minimum": 0,
                        "description": "Цена единицы в центах"
                    },
                    "category": {
                        "type": "string",
                        "example": "Одежда"
                    },
                    "hs_code": {
                        "type": "string",
                        "description": "Код ТН ВЭД (необязательно)"
                    },
                    "origin_country": {
                        "type": "string",
                        "example": "US"
                    }
                }
            },
            "Shipment": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "reference": {
                        "type": "string",
                        "nullable": true,
                        "description": "Ваш номер заказа"
                    },
                    "status": {
                        "type": "string",
                        "example": "label_ready"
                    },
                    "carrier": {
                        "type": "string"
                    },
                    "service": {
                        "type": "string"
                    },
                    "tracking_number": {
                        "type": "string",
                        "nullable": true
                    },
                    "price_cents": {
                        "type": "integer"
                    },
                    "currency": {
                        "type": "string",
                        "example": "USD"
                    },
                    "from": {
                        "$ref": "#/components/schemas/ShipmentAddress"
                    },
                    "to": {
                        "$ref": "#/components/schemas/ShipmentAddress"
                    },
                    "declared_value_cents": {
                        "type": "integer"
                    },
                    "chargeable_weight_g": {
                        "type": "integer",
                        "nullable": true
                    },
                    "label_available": {
                        "type": "boolean"
                    },
                    "eta_from": {
                        "type": "string",
                        "format": "date",
                        "nullable": true
                    },
                    "eta_to": {
                        "type": "string",
                        "format": "date",
                        "nullable": true
                    },
                    "source": {
                        "type": "string",
                        "enum": [
                            "web",
                            "api"
                        ]
                    },
                    "created_at": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "delivered_at": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                    },
                    "cancelled_at": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                    }
                }
            }
        }
    }
}