{
  "openapi": "3.1.0",
  "info": {
    "title": "Torgo Product API",
    "version": "1.2.0",
    "description": "Добавление товаров в собственный каталог базы/магазина/склада. JSON, CSV, XLS, YML/SATU XML, CommerceML 2.x и 3.1, до пяти XML (товары, предложения, цены, остатки, справочники), 15 MB суммарно. Только новые позиции, не синхронизация и не заказы. До 2000 товаров/5 MB на файл, 30 запросов в минуту. Полная документация https://kz.torgo.biz/api_docs.php Необязательный source_id + полный external_id сохраняют GUID→product_id без дублей. Повтор возвращает прежний ID; изменённые поля отмечаются update_required. Обновления существующих цен/остатков пока нет. Точное первое связывание требует adopt_existing."
  },
  "servers": [
    {
      "url": "https://kz.torgo.biz"
    }
  ],
  "security": [
    {
      "ProductKey": []
    }
  ],
  "components": {
    "securitySchemes": {
      "ProductKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Персональный ключ из кабинета; срок 90 дней"
      }
    }
  },
  "paths": {
    "/api_products.php": {
      "get": {
        "operationId": "getProductImportContext",
        "summary": "Свой каталог, разделы, форматы и лимиты",
        "responses": {
          "200": {
            "description": "Контекст своего каталога или повтор завершённого запроса",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Товары добавлены; data: imported/skipped/parsed/replayed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Нет Idempotency-Key или параметры URL",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Неверный/просроченный/отозванный ключ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Аккаунт недоступен",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Конфликт ключа запроса или профиль магазина неполон",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "413": {
            "description": "Превышение размера",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "415": {
            "description": "Неверный Content-Type",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Некорректный файл/поле",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Лимит запросов; Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Временная ошибка; повторять с тем же ключом",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "addProducts",
        "summary": "Добавить товары списком или файлом",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{8,100}$"
            },
            "description": "Новый идентификатор логического импорта. При повторе сохранить тело/файлы и параметры"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "products"
                ],
                "additionalProperties": false,
                "properties": {
                  "products": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 2000,
                    "items": {
                      "type": "object",
                      "required": [
                        "name"
                      ],
                      "additionalProperties": false,
                      "properties": {
                        "name": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 120,
                          "description": "Лимит базы 35, магазина 45, склада 120"
                        },
                        "unit": {
                          "type": "string",
                          "maxLength": 6
                        },
                        "price": {
                          "oneOf": [
                            {
                              "type": "string",
                              "pattern": "^[0-9]{1,9}([.,][0-9]{1,4})?$"
                            },
                            {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 999999999
                            }
                          ]
                        },
                        "quantity": {
                          "oneOf": [
                            {
                              "type": "string",
                              "pattern": "^[0-9]{1,9}([.,][0-9]{1,4})?$"
                            },
                            {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 999999999
                            }
                          ]
                        },
                        "article": {
                          "type": "string",
                          "maxLength": 25
                        },
                        "description": {
                          "type": "string",
                          "maxLength": 2000
                        },
                        "external_id": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 255,
                          "description": "Обязательно с source_id: полный GUID/товар#вариант, 1–255 UTF-8 байт, без управляющих символов и пробелов по краям. Регистр учитывается"
                        }
                      }
                    }
                  },
                  "options": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "department_id": {
                        "type": "integer",
                        "minimum": 0,
                        "description": "Только свой раздел базы из GET"
                      },
                      "visible_base": {
                        "type": "boolean"
                      },
                      "visible_market": {
                        "type": "boolean"
                      },
                      "visible_customer": {
                        "type": "boolean"
                      },
                      "price_type_id": {
                        "type": "string",
                        "maxLength": 100,
                        "description": "ИдТипаЦены для CommerceML"
                      },
                      "source_id": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 64,
                        "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$",
                        "description": "Постоянное имя подключения в вашем аккаунте. CommerceML или JSON с external_id; настройки раздела, видимости, типа цены и склада фиксируются при первом импорте"
                      },
                      "adopt_existing": {
                        "type": "boolean",
                        "default": false,
                        "description": "С source_id: разрешить первое точное связывание существующей позиции без изменения её полей"
                      }
                    }
                  }
                },
                "allOf": [
                  {
                    "if": {
                      "required": [
                        "options"
                      ],
                      "properties": {
                        "options": {
                          "required": [
                            "source_id"
                          ]
                        }
                      }
                    },
                    "then": {
                      "properties": {
                        "products": {
                          "items": {
                            "required": [
                              "external_id"
                            ]
                          }
                        }
                      }
                    }
                  }
                ]
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "format",
                  "file"
                ],
                "additionalProperties": false,
                "properties": {
                  "format": {
                    "type": "string",
                    "enum": [
                      "json",
                      "csv",
                      "xls",
                      "xml",
                      "yml",
                      "commerceml"
                    ]
                  },
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "До 5 MB. JSON — список, CSV/XLS — A-F без заголовка, XML — YML или CommerceML"
                  },
                  "offers_file": {
                    "type": "string",
                    "format": "binary",
                    "description": "Второй файл CommerceML до 5 MB"
                  },
                  "department_id": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "visible_base": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ]
                  },
                  "visible_market": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ]
                  },
                  "visible_customer": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ]
                  },
                  "price_type_id": {
                    "type": "string",
                    "maxLength": 100
                  },
                  "prices_file": {
                    "type": "string",
                    "format": "binary",
                    "description": "Цены предложений CommerceML, до 5 MB; все части одного каталога"
                  },
                  "rests_file": {
                    "type": "string",
                    "format": "binary",
                    "description": "Остатки предложений CommerceML, до 5 MB; все части одного каталога"
                  },
                  "classifier_file": {
                    "type": "string",
                    "format": "binary",
                    "description": "Корневой import.xml со справочником единиц и типов цен, до 5 MB; все части одного каталога"
                  },
                  "warehouse_id": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Ид склада в исходной 1С; нужен при нескольких складах без общего остатка. Только CommerceML"
                  },
                  "source_id": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$",
                    "description": "Постоянное имя подключения в вашем аккаунте. CommerceML или JSON с external_id; настройки раздела, видимости, типа цены и склада фиксируются при первом импорте"
                  },
                  "adopt_existing": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ],
                    "default": 0,
                    "description": "Явное первое связывание точного совпадения, только с source_id"
                  }
                },
                "description": "До пяти файлов по 5 MB, до 15 MB суммарно. KZT, совпадение каталога и Ид; неполные цены/остатки отклоняют импорт. Без обновления существующих товаров С source_id доступен CommerceML/JSON; CSV/XLS/YML требуют обычного режима без GUID."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Контекст своего каталога или повтор завершённого запроса; с source_id также linked/updates_required/bindings; существующий каталог не изменяется",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "imported": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "skipped": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "parsed": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "linked": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "updates_required": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "replayed": {
                          "type": "boolean"
                        },
                        "bindings": {
                          "type": "array",
                          "maxItems": 2000,
                          "items": {
                            "type": "object",
                            "required": [
                              "external_id",
                              "product_id",
                              "status"
                            ],
                            "properties": {
                              "external_id": {
                                "type": "string"
                              },
                              "product_id": {
                                "type": "integer",
                                "minimum": 1
                              },
                              "status": {
                                "type": "string",
                                "enum": [
                                  "created",
                                  "linked",
                                  "matched",
                                  "update_required"
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Товары добавлены; data: imported/skipped/parsed/replayed; с source_id также linked/updates_required/bindings; существующий каталог не изменяется",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "imported": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "skipped": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "parsed": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "linked": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "updates_required": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "replayed": {
                          "type": "boolean"
                        },
                        "bindings": {
                          "type": "array",
                          "maxItems": 2000,
                          "items": {
                            "type": "object",
                            "required": [
                              "external_id",
                              "product_id",
                              "status"
                            ],
                            "properties": {
                              "external_id": {
                                "type": "string"
                              },
                              "product_id": {
                                "type": "integer",
                                "minimum": 1
                              },
                              "status": {
                                "type": "string",
                                "enum": [
                                  "created",
                                  "linked",
                                  "matched",
                                  "update_required"
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Нет Idempotency-Key или параметры URL",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Неверный/просроченный/отозванный ключ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Аккаунт недоступен",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Конфликт ключа запроса или профиль магазина неполон; external_source_changed/external_product_missing/external_product_unbound/external_product_ambiguous/external_binding_conflict — весь пакет откатывается",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "413": {
            "description": "Превышение размера",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "415": {
            "description": "Неверный Content-Type",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Некорректный файл/поле",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Лимит запросов; Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Временная ошибка; повторять с тем же ключом",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
