Product API

Product API для управлСния Ρ‚ΠΎΠ²Π°Ρ€Π°ΠΌΠΈ Π² ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π΅ ΠΏΡ€ΠΎΠ΄Π°Π²Ρ†Π° с 23 ΠΌΠ΅Ρ‚ΠΎΠ΄Π°ΠΌΠΈ для комплСксного управлСния Ρ‚ΠΎΠ²Π°Ρ€Π½Ρ‹ΠΌ ассортимСнтом.

ΠžΠ±Π·ΠΎΡ€

Product API обСспСчиваСт ΠΏΠΎΠ»Π½Ρ‹ΠΉ ΠΆΠΈΠ·Π½Π΅Π½Π½Ρ‹ΠΉ Ρ†ΠΈΠΊΠ» Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ² ΠΎΡ‚ создания Π΄ΠΎ архивирования. Π’ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ ΡƒΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΠ΅ Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Π°ΠΌΠΈ, изобраТСниями, SKU, Ρ†Π΅Π½Π°ΠΌΠΈ, остатками ΠΈ ΠΌΠ΅Ρ‚Π°ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΠ΅ΠΉ.

ΠžΡΠ½ΠΎΠ²Π½Ρ‹Π΅ возмоТности:

  • πŸ“¦ АрхивированиС ΠΈ восстановлСниС Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²
  • πŸ“‹ ΠŸΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΠ΅ списков Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ² с Ρ„ΠΈΠ»ΡŒΡ‚Ρ€Π°Ρ†ΠΈΠ΅ΠΉ
  • πŸ”§ ОбновлСниС Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠΎΠ² ΠΈ характСристик
  • πŸ“€ Π˜ΠΌΠΏΠΎΡ€Ρ‚ Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ² ΠΏΠΎ SKU
  • πŸ–ΌοΈ Π£ΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΠ΅ изобраТСниями
  • πŸ“Š ΠœΠΎΠ½ΠΈΡ‚ΠΎΡ€ΠΈΠ½Π³ Ρ†Π΅Π½ ΠΈ остатков
  • ⭐ Анализ Ρ€Π΅ΠΉΡ‚ΠΈΠ½Π³ΠΎΠ² ΠΈ ΠΎΡ‚Π·Ρ‹Π²ΠΎΠ²
  • πŸ”— БвязанныС SKU ΠΈ Ρ€Π΅ΠΊΠΎΠΌΠ΅Π½Π΄Π°Ρ†ΠΈΠΈ

ДоступныС ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹

Π£ΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΆΠΈΠ·Π½Π΅Π½Π½Ρ‹ΠΌ Ρ†ΠΈΠΊΠ»ΠΎΠΌ Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²

archiveProducts(request) - АрхивированиС Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²

const result = await productApi.archiveProducts({
  product_id: [123456, 789012, 345678]
});

unarchiveProducts(request) - Π Π°Π·Π°Ρ€Ρ…ΠΈΠ²ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²

const result = await productApi.unarchiveProducts({
  product_id: [123456, 789012]
});

deleteProducts(request) - Π£Π΄Π°Π»Π΅Π½ΠΈΠ΅ Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²

const result = await productApi.deleteProducts({
  offers: [
    { offer_id: "ITEM001" },
    { product_id: 123456 }
  ]
});

ΠŸΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΠ΅ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΠΈ ΠΎ Ρ‚ΠΎΠ²Π°Ρ€Π°Ρ…

getProductsList(request) - Бписок Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²

const products = await productApi.getProductsList({
  filter: {
    offer_id: ["ITEM001", "ITEM002"],
    visibility: "VISIBLE"
  },
  limit: 100
});

getProductInfo(request) - ΠŸΠΎΠ΄Ρ€ΠΎΠ±Π½Π°Ρ информация ΠΎ Ρ‚ΠΎΠ²Π°Ρ€Π΅

const info = await productApi.getProductInfo({
  sku: 987654321,
  offer_id: "ITEM001",
  product_id: 123456
});

getProductInfoListV3(request) - Π Π°ΡΡˆΠΈΡ€Π΅Π½Π½Π°Ρ информация V3

const infoList = await productApi.getProductInfoListV3({
  filter: {
    offer_id: ["ITEM001", "ITEM002"],
    product_id: [123456, 789012]
  },
  limit: 50
});

Π˜ΠΌΠΏΠΎΡ€Ρ‚ ΠΈ ΡƒΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΠ΅ Ρ‚ΠΎΠ²Π°Ρ€Π°ΠΌΠΈ

importProductsBySku(request) - Π˜ΠΌΠΏΠΎΡ€Ρ‚ ΠΏΠΎ SKU

const importResult = await productApi.importProductsBySku({
  items: [
    { sku: 987654321, offer_id: "ITEM001" },
    { sku: 123456789, offer_id: "ITEM002" }
  ]
});

importProducts(request) - ΠžΠ±Ρ‰ΠΈΠΉ ΠΈΠΌΠΏΠΎΡ€Ρ‚ Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²

const result = await productApi.importProducts({
  items: [
    {
      offer_id: "NEW_ITEM",
      barcode: "1234567890123",
      category_id: 15621,
      name: "Новый Ρ‚ΠΎΠ²Π°Ρ€",
      price: "1500",
      old_price: "2000",
      currency_code: "RUB",
      attributes: [
        {
          complex_id: 0,
          id: 85,
          values: [{ dictionary_value_id: 971082156 }]
        }
      ]
    }
  ]
});

getImportProductsInfo(request) - Бтатус ΠΈΠΌΠΏΠΎΡ€Ρ‚Π°

const status = await productApi.getImportProductsInfo({
  task_id: "task_123456"
});

Π£ΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΠ΅ Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Π°ΠΌΠΈ ΠΈ характСристиками

updateProductAttributes(request) - ОбновлСниС Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠΎΠ²

const result = await productApi.updateProductAttributes({
  items: [
    {
      offer_id: "ITEM001",
      attributes: [
        {
          complex_id: 0,
          id: 85,
          values: [{ dictionary_value_id: 971082156 }]
        }
      ]
    }
  ]
});

getProductAttributes(request) - Атрибуты Ρ‚ΠΎΠ²Π°Ρ€Π°

const attributes = await productApi.getProductAttributes({
  filter: {
    offer_id: ["ITEM001"],
    visibility: "VISIBLE"
  },
  limit: 100
});

getCertificationTypes(request) - Π’ΠΈΠΏΡ‹ сСртификации

const certTypes = await productApi.getCertificationTypes({
  category_id: 15621,
  type_id: 1
});

Π£ΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΠ΅ изобраТСниями

importProductPictures(request) - Π˜ΠΌΠΏΠΎΡ€Ρ‚ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ

const result = await productApi.importProductPictures({
  product_id: 123456,
  images: [
    {
      file_name: "product1.jpg",
      url: "https://example.com/images/product1.jpg"
    },
    {
      file_name: "product2.jpg",
      url: "https://example.com/images/product2.jpg"
    }
  ]
});

getProductPictures(request) - ΠŸΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΠ΅ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ

const pictures = await productApi.getProductPictures({
  product_id: [123456, 789012]
});

Π¦Π΅Π½Ρ‹ ΠΈ остатки

getProductStocks(request) - ΠžΡΡ‚Π°Ρ‚ΠΊΠΈ Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²

const stocks = await productApi.getProductStocks({
  filter: {
    offer_id: ["ITEM001", "ITEM002"],
    visibility: "VISIBLE"
  },
  limit: 100
});

getProductPrices(request) - Π¦Π΅Π½Ρ‹ Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²

const prices = await productApi.getProductPrices({
  filter: {
    offer_id: ["ITEM001", "ITEM002"],
    visibility: "VISIBLE"
  },
  limit: 100
});

Π Π΅ΠΉΡ‚ΠΈΠ½Π³ΠΈ ΠΈ Π°Π½Π°Π»ΠΈΡ‚ΠΈΠΊΠ°

getProductRating(request) - Π Π΅ΠΉΡ‚ΠΈΠ½Π³ Ρ‚ΠΎΠ²Π°Ρ€Π°

const rating = await productApi.getProductRating({
  products: [
    { offer_id: "ITEM001" },
    { sku: 987654321 }
  ]
});

getRelatedSKU(request) - БвязанныС SKU

const relatedSku = await productApi.getRelatedSKU({
  sku: [987654321, 123456789]
});

Π”ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Π°Ρ информация

getDiscountedProductInfo(request) - Π˜Π½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡ ΠΎΠ± ΡƒΡ†Π΅Π½ΠΊΠ΅

const discountedInfo = await productApi.getDiscountedProductInfo({
  discounted_skus: ["987654321", "123456789"]
});

getProductDescription(request) - ОписаниС Ρ‚ΠΎΠ²Π°Ρ€Π°

const description = await productApi.getProductDescription({
  offer_id: "ITEM001",
  product_id: 123456
});

getProductSubscription(request) - Подписки Π½Π° Ρ‚ΠΎΠ²Π°Ρ€

const subscription = await productApi.getProductSubscription({
  offer_id: "ITEM001",
  sku: 987654321
});

getUploadQuota(request) - ΠšΠ²ΠΎΡ‚Π° Π·Π°Π³Ρ€ΡƒΠ·ΠΊΠΈ

const quota = await productApi.getUploadQuota();

updateOfferID(request) - ОбновлСниС Π°Ρ€Ρ‚ΠΈΠΊΡƒΠ»Π°

const result = await productApi.updateOfferID({
  update_offer_id: [
    {
      offer_id: "OLD_ITEM",
      new_offer_id: "NEW_ITEM"
    }
  ]
});

TypeScript интСрфСйсы

// ΠžΡΠ½ΠΎΠ²Π½Ρ‹Π΅ запросы
interface ProductArchiveRequest {
  product_id: number[];
}

interface ProductUnarchiveRequest {
  product_id: number[];
}

interface ProductListRequest {
  filter: {
    offer_id?: string[];
    product_id?: number[];
    visibility?: "VISIBLE" | "INVISIBLE" | "EMPTY_STOCK" | "NOT_MODERATED" | "MODERATED" | "DISABLED" | "STATE_FAILED_MODERATION" | "READY_TO_SUPPLY" | "VALIDATION_STATE_PENDING" | "VALIDATION_STATE_FAIL" | "VALIDATION_STATE_SUCCESS" | "TO_SUPPLY" | "IN_SALE" | "REMOVED_FROM_SALE" | "BANNED" | "OVERPRICED" | "CRITICALLY_OVERPRICED" | "EMPTY_BARCODE" | "BARCODE_EXISTS" | "QUARANTINE" | "ARCHIVED" | "OVERPRICED_WITH_STOCK" | "PARTIAL_APPROVED" | "IMAGE_ABSENT" | "MODERATION_BLOCK";
  };
  sort?: "created_at" | "updated_at" | "price" | "name";
  sort_dir?: "asc" | "desc";
  limit: number;
  last_id?: string;
}

interface ProductInfoRequest {
  sku?: number;
  offer_id?: string;
  product_id?: number;
}

interface ProductImportBySKURequest {
  items: Array<{
    sku: number;
    offer_id: string;
  }>;
}

interface ProductImportRequest {
  items: Array<{
    offer_id: string;
    barcode?: string;
    category_id?: number;
    name?: string;
    price?: string;
    old_price?: string;
    currency_code?: string;
    vat?: string;
    height?: number;
    depth?: number;
    width?: number;
    dimension_unit?: string;
    weight?: number;
    weight_unit?: string;
    images?: Array<{
      file_name: string;
      default?: boolean;
    }>;
    attributes: Array<{
      complex_id: number;
      id: number;
      values: Array<{
        dictionary_value_id?: number;
        value?: string;
      }>;
    }>;
  }>;
}

interface ProductAttributesUpdateRequest {
  items: Array<{
    offer_id: string;
    attributes: Array<{
      complex_id: number;
      id: number;
      values: Array<{
        dictionary_value_id?: number;
        value?: string;
      }>;
    }>;
  }>;
}

interface ProductPicturesImportRequest {
  product_id: number;
  images: Array<{
    file_name: string;
    url: string;
  }>;
}

interface ProductOfferIDUpdateRequest {
  update_offer_id: Array<{
    offer_id: string;
    new_offer_id: string;
  }>;
}

interface ProductDeleteRequest {
  offers: Array<{
    offer_id?: string;
    product_id?: number;
  }>;
}

// ΠžΡ‚Π²Π΅Ρ‚Ρ‹
interface ProductListResponse {
  items: Array<{
    product_id: number;
    offer_id: string;
    is_fbo_visible: boolean;
    is_fbs_visible: boolean;
    archived: boolean;
    is_discounted: boolean;
  }>;
  total: number;
  last_id: string;
}

interface ProductInfoResponse {
  product_id: number;
  offer_id: string;
  barcode: string;
  category_id: number;
  name: string;
  offer_ids: string[];
  price: string;
  old_price: string;
  premium_price: string;
  currency_code: string;
  marketing_price: string;
  min_ozon_price: string;
  min_price: string;
  sources: Array<{
    is_enabled: boolean;
    sku: number;
    source: string;
  }>;
  stocks: Array<{
    coming: number;
    present: number;
    reserved: number;
    type: string;
  }>;
  errors: string[];
  vat: string;
  visible: boolean;
  visibility_details: {
    has_price: boolean;
    has_stock: boolean;
    active_product: boolean;
  };
  price_index: string;
  images: Array<{
    file_name: string;
    default: boolean;
    index: number;
  }>;
  image360: string[];
  pdf_list: Array<{
    index: number;
    name: string;
    src_url: string;
  }>;
  attributes: Array<{
    attribute_id: number;
    complex_id: number;
    values: Array<{
      dictionary_value_id: number;
      value: string;
    }>;
  }>;
  complex_attributes: any[];
  color_image: string;
  last_id: string;
  weight: number;
  dimensions: {
    height: number;
    length: number;
    weight: number;
    width: number;
  };
  description_category_id: number;
  type_id: number;
  is_kgt: boolean;
  sku: number;
  rating: string;
  tax_rate: string;
  discounted_stocks: {
    coming: number;
    present: number;
    reserved: number;
  };
  is_prepayment: boolean;
  is_prepayment_allowed: boolean;
  images360: any[];
  has_discounted_item: boolean;
  barcodes: string[];
  updated_at: string;
  price_indexes: {
    external_index_data: {
      minimal_price: string;
      minimal_price_currency: string;
      price_index_value: number;
    };
    ozon_index_data: {
      minimal_price: string;
      minimal_price_currency: string;
      price_index_value: number;
    };
    price_index: string;
    self_marketplaces_index_data: {
      minimal_price: string;
      minimal_price_currency: string;
      price_index_value: number;
    };
  };
  status: {
    state: string;
    state_failed_moderation_reasons: string[];
    moderate_status: string;
    decline_reasons: string[];
    validation_state: string;
    state_name: string;
    state_description: string;
    is_failed_moderation: boolean;
    is_created: boolean;
    state_tooltip: string;
    item_errors: Array<{
      code: string;
      field: string;
      attribute_id: number;
      attribute_name: string;
      optional_description_elements: any;
      state_description: string;
      level: string;
    }>;
    state_updated_at: string;
  };
  state: string;
  service_type: string;
  fbo_sku: number;
  fbs_sku: number;
  currency_code2: string;
  tags: any[];
  loyalty_earn_rate: number;
  created_at: string;
  parent_id: number;
  rich_content_json: string;
  primary_image: string;
  brand: string;
  acquisition?: {
    url: string;
    text: string;
  };
}

interface ProductImportResponse {
  task_id: string;
}

interface ProductImportInfoResponse {
  result: Array<{
    offer_id: string;
    product_id: number;
    status: string;
    errors: Array<{
      code: string;
      message: string;
    }>;
  }>;
}

interface ProductAttributesResponse {
  items: Array<{
    product_id: number;
    offer_id: string;
    attributes: Array<{
      attribute_id: number;
      complex_id: number;
      values: Array<{
        dictionary_value_id: number;
        value: string;
      }>;
    }>;
  }>;
  total: number;
  last_id: string;
}

interface ProductCertificationTypesResponse {
  certificate_types: Array<{
    id: number;
    name: string;
    is_required: boolean;
  }>;
}

interface ProductPicturesImportResponse {
  pictures: Array<{
    product_id: number;
    status: string;
    url: string;
    error: string;
  }>;
}

interface ProductPicturesResponse {
  items: Array<{
    product_id: number;
    images: Array<{
      file_name: string;
      default: boolean;
      index: number;
    }>;
  }>;
}

interface ProductRatingResponse {
  products: Array<{
    offer_id: string;
    sku: number;
    rating: string;
    groups: Array<{
      key: string;
      rating: string;
      count: number;
    }>;
  }>;
}

interface RelatedSKUResponse {
  items: Array<{
    sku: number;
    related_skus: number[];
  }>;
}

interface DiscountedProductInfoResponse {
  items: Array<{
    discounted_sku: number;
    original_sku: number;
    condition: string;
    defects: string[];
    discount_percentage: number;
  }>;
}

interface ProductDescriptionResponse {
  description: string;
  short_description: string;
  rich_content_json: string;
}

interface ProductSubscriptionResponse {
  subscription_info: {
    subscription_plan: string;
    is_auto_renewal: boolean;
    next_payment_date: string;
    status: string;
  };
}

interface UploadQuotaResponse {
  quota: {
    used: number;
    limit: number;
    reset_date: string;
  };
}

interface UpdateOfferIDResponse {
  errors: Array<{
    offer_id: string;
    error: string;
  }>;
}

interface DeleteProductsResponse {
  status: Array<{
    is_deleted: boolean;
    offer_id: string;
    product_id: number;
    error: string;
  }>;
}

ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ использования

Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ Π½ΠΎΠ²ΠΎΠ³ΠΎ Ρ‚ΠΎΠ²Π°Ρ€Π°

// 1. Π˜ΠΌΠΏΠΎΡ€Ρ‚ Ρ‚ΠΎΠ²Π°Ρ€Π°
const importResult = await productApi.importProducts({
  items: [
    {
      offer_id: "SMARTPHONE_001",
      barcode: "1234567890123",
      category_id: 15621,
      name: "Π‘ΠΌΠ°Ρ€Ρ‚Ρ„ΠΎΠ½ Premium XY",
      price: "45000",
      old_price: "50000",
      currency_code: "RUB",
      vat: "0.20",
      height: 150,
      depth: 10,
      width: 75,
      dimension_unit: "mm",
      weight: 200,
      weight_unit: "g",
      images: [
        { file_name: "smartphone_main.jpg", default: true },
        { file_name: "smartphone_side.jpg", default: false }
      ],
      attributes: [
        {
          complex_id: 0,
          id: 85, // Π‘Ρ€Π΅Π½Π΄
          values: [{ dictionary_value_id: 971082156 }]
        },
        {
          complex_id: 0,
          id: 5076, // Π¦Π²Π΅Ρ‚
          values: [{ value: "Π§Π΅Ρ€Π½Ρ‹ΠΉ" }]
        }
      ]
    }
  ]
});

// 2. ΠŸΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° статуса ΠΈΠΌΠΏΠΎΡ€Ρ‚Π°
const status = await productApi.getImportProductsInfo({
  task_id: importResult.task_id
});

// 3. Π”ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ
if (status.result[0].status === "imported") {
  await productApi.importProductPictures({
    product_id: status.result[0].product_id,
    images: [
      {
        file_name: "smartphone_main.jpg",
        url: "https://example.com/images/smartphone_main.jpg"
      },
      {
        file_name: "smartphone_side.jpg", 
        url: "https://example.com/images/smartphone_side.jpg"
      }
    ]
  });
}

Π£ΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΎΠΌ Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²

// ΠŸΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΠ΅ списка Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ² с Ρ„ΠΈΠ»ΡŒΡ‚Ρ€Π°Ρ†ΠΈΠ΅ΠΉ
const productsList = await productApi.getProductsList({
  filter: {
    visibility: "VISIBLE",
    offer_id: ["SMARTPHONE_001", "TABLET_002"]
  },
  sort: "updated_at",
  sort_dir: "desc",
  limit: 50
});

// ΠŸΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΠ΅ ΠΏΠΎΠ΄Ρ€ΠΎΠ±Π½ΠΎΠΉ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΠΈ
const productInfo = await productApi.getProductInfo({
  offer_id: "SMARTPHONE_001"
});

// ОбновлСниС Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠΎΠ²
await productApi.updateProductAttributes({
  items: [
    {
      offer_id: "SMARTPHONE_001",
      attributes: [
        {
          complex_id: 0,
          id: 5076, // Π¦Π²Π΅Ρ‚
          values: [{ value: "Π‘ΠΈΠ½ΠΈΠΉ" }]
        },
        {
          complex_id: 0,
          id: 8229, // ΠŸΠ°ΠΌΡΡ‚ΡŒ
          values: [{ value: "128 Π“Π‘" }]
        }
      ]
    }
  ]
});

Анализ ΠΏΡ€ΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²

// Π Π΅ΠΉΡ‚ΠΈΠ½Π³ Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²
const ratings = await productApi.getProductRating({
  products: [
    { offer_id: "SMARTPHONE_001" },
    { offer_id: "TABLET_002" },
    { sku: 987654321 }
  ]
});

ratings.products.forEach(product => {
  console.log(`Π’ΠΎΠ²Π°Ρ€ ${product.offer_id}: Ρ€Π΅ΠΉΡ‚ΠΈΠ½Π³ ${product.rating}`);
  product.groups.forEach(group => {
    console.log(`  ${group.key}: ${group.rating} (${group.count} ΠΎΡ‚Π·Ρ‹Π²ΠΎΠ²)`);
  });
});

// БвязанныС Ρ‚ΠΎΠ²Π°Ρ€Ρ‹
const relatedSkus = await productApi.getRelatedSKU({
  sku: [987654321, 123456789]
});

relatedSkus.items.forEach(item => {
  console.log(`SKU ${item.sku} связан с: ${item.related_skus.join(", ")}`);
});

Π‘Π»ΠΎΠΆΠ½Ρ‹Π΅ сцСнарии

ProductCatalogManager - БистСма управлСния ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΎΠΌ

class ProductCatalogManager {
  constructor(private api: ProductApi) {}

  async createProductFamily(familyData: ProductFamilyData): Promise<ProductFamily> {
    const tasks: string[] = [];
    
    // Π˜ΠΌΠΏΠΎΡ€Ρ‚ всСх Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ² сСмСйства
    for (const product of familyData.products) {
      const importResult = await this.api.importProducts({
        items: [product]
      });
      tasks.push(importResult.task_id);
    }

    // ОТиданиС Π·Π°Π²Π΅Ρ€ΡˆΠ΅Π½ΠΈΡ ΠΈΠΌΠΏΠΎΡ€Ρ‚Π°
    const results = await Promise.all(
      tasks.map(taskId => this.waitForImportCompletion(taskId))
    );

    // Π”ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ
    await Promise.all(
      results.map(result => this.addProductImages(result))
    );

    return {
      family_id: familyData.family_id,
      products: results,
      created_at: new Date().toISOString()
    };
  }

  private async waitForImportCompletion(taskId: string): Promise<ProductImportResult> {
    let attempts = 0;
    const maxAttempts = 30;

    while (attempts < maxAttempts) {
      const status = await this.api.getImportProductsInfo({ task_id: taskId });
      
      if (status.result[0].status === "imported") {
        return status.result[0];
      }
      
      if (status.result[0].status === "failed") {
        throw new Error(`Import failed: ${status.result[0].errors.map(e => e.message).join(", ")}`);
      }

      await new Promise(resolve => setTimeout(resolve, 2000));
      attempts++;
    }

    throw new Error("Import timeout");
  }

  private async addProductImages(result: ProductImportResult): Promise<void> {
    if (result.images && result.images.length > 0) {
      await this.api.importProductPictures({
        product_id: result.product_id,
        images: result.images
      });
    }
  }

  async optimizeCatalog(): Promise<CatalogOptimizationReport> {
    // ΠŸΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΠ΅ всСх Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²
    const allProducts = await this.getAllProducts();
    
    // Анализ ΠΏΡ€ΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ
    const performanceAnalysis = await this.analyzePerformance(allProducts);
    
    // Π Π΅ΠΊΠΎΠΌΠ΅Π½Π΄Π°Ρ†ΠΈΠΈ ΠΏΠΎ ΠΎΠΏΡ‚ΠΈΠΌΠΈΠ·Π°Ρ†ΠΈΠΈ
    return {
      total_products: allProducts.length,
      performance_analysis: performanceAnalysis,
      recommendations: this.generateRecommendations(performanceAnalysis)
    };
  }

  private async getAllProducts(): Promise<ProductInfo[]> {
    const products: ProductInfo[] = [];
    let lastId = "";

    do {
      const response = await this.api.getProductsList({
        filter: { visibility: "VISIBLE" },
        limit: 1000,
        last_id: lastId || undefined
      });

      for (const product of response.items) {
        const detailedInfo = await this.api.getProductInfo({
          product_id: product.product_id
        });
        products.push(detailedInfo);
      }

      lastId = response.last_id;
    } while (lastId);

    return products;
  }
}

interface ProductFamilyData {
  family_id: string;
  products: ProductImportRequest['items'];
}

interface ProductFamily {
  family_id: string;
  products: ProductImportResult[];
  created_at: string;
}

interface ProductImportResult {
  offer_id: string;
  product_id: number;
  status: string;
  images?: Array<{ file_name: string; url: string; }>;
}

interface CatalogOptimizationReport {
  total_products: number;
  performance_analysis: PerformanceAnalysis;
  recommendations: string[];
}

interface PerformanceAnalysis {
  low_rating_products: number;
  missing_images: number;
  incomplete_attributes: number;
  archive_candidates: number;
}

AutomatedProductAnalyzer - БистСма Π°Π½Π°Π»ΠΈΡ‚ΠΈΠΊΠΈ Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²

class AutomatedProductAnalyzer {
  constructor(private api: ProductApi) {}

  async generateInsightsReport(filters?: ProductListRequest['filter']): Promise<ProductInsightsReport> {
    // ΠŸΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΠ΅ Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ² для Π°Π½Π°Π»ΠΈΠ·Π°
    const products = await this.getProductsForAnalysis(filters);
    
    // ΠŸΠ°Ρ€Π°Π»Π»Π΅Π»ΡŒΠ½Ρ‹ΠΉ сбор Π΄Π°Π½Π½Ρ‹Ρ…
    const [ratings, stocks, prices, relatedData] = await Promise.all([
      this.collectRatingsData(products),
      this.collectStocksData(products),
      this.collectPricesData(products),
      this.collectRelatedSkuData(products)
    ]);

    // Анализ Ρ‚Ρ€Π΅Π½Π΄ΠΎΠ²
    const trends = this.analyzeTrends(products, ratings, stocks, prices);
    
    // ГСнСрация Ρ€Π΅ΠΊΠΎΠΌΠ΅Π½Π΄Π°Ρ†ΠΈΠΉ
    const recommendations = this.generateActionableRecommendations(
      products, ratings, stocks, prices, relatedData
    );

    return {
      analysis_date: new Date().toISOString(),
      products_analyzed: products.length,
      ratings_analysis: this.analyzeRatings(ratings),
      inventory_analysis: this.analyzeInventory(stocks),
      pricing_analysis: this.analyzePricing(prices),
      trends_analysis: trends,
      cross_selling_opportunities: this.findCrossSelling(relatedData),
      actionable_recommendations: recommendations
    };
  }

  private async collectRatingsData(products: ProductInfo[]): Promise<Map<string, ProductRating>> {
    const ratingsMap = new Map<string, ProductRating>();
    const chunkSize = 100;

    for (let i = 0; i < products.length; i += chunkSize) {
      const chunk = products.slice(i, i + chunkSize);
      const ratingsResponse = await this.api.getProductRating({
        products: chunk.map(p => ({ offer_id: p.offer_id }))
      });

      ratingsResponse.products.forEach(rating => {
        ratingsMap.set(rating.offer_id, rating);
      });

      // Rate limiting
      await new Promise(resolve => setTimeout(resolve, 100));
    }

    return ratingsMap;
  }

  private generateActionableRecommendations(
    products: ProductInfo[],
    ratings: Map<string, ProductRating>,
    stocks: Map<string, ProductStock>,
    prices: Map<string, ProductPrice>,
    relatedData: Map<number, number[]>
  ): ActionableRecommendation[] {
    const recommendations: ActionableRecommendation[] = [];

    products.forEach(product => {
      const rating = ratings.get(product.offer_id);
      const stock = stocks.get(product.offer_id);
      const price = prices.get(product.offer_id);

      // Низкий Ρ€Π΅ΠΉΡ‚ΠΈΠ½Π³
      if (rating && parseFloat(rating.rating) < 4.0) {
        recommendations.push({
          type: "quality_improvement",
          priority: "high",
          offer_id: product.offer_id,
          action: "Анализ ΠΎΡ‚Π·Ρ‹Π²ΠΎΠ² ΠΈ ΡƒΠ»ΡƒΡ‡ΡˆΠ΅Π½ΠΈΠ΅ качСства Ρ‚ΠΎΠ²Π°Ρ€Π°",
          expected_impact: "ΠŸΠΎΠ²Ρ‹ΡˆΠ΅Π½ΠΈΠ΅ Ρ€Π΅ΠΉΡ‚ΠΈΠ½Π³Π° Π½Π° 0.5+ Π±Π°Π»Π»ΠΎΠ²"
        });
      }

      // Π˜Π·Π±Ρ‹Ρ‚ΠΎΡ‡Π½Ρ‹Π΅ остатки
      if (stock && stock.present > 100 && stock.reserved < 10) {
        recommendations.push({
          type: "inventory_optimization",
          priority: "medium",
          offer_id: product.offer_id,
          action: "ΠŸΡ€ΠΎΠ²Π΅Π΄Π΅Π½ΠΈΠ΅ Π°ΠΊΡ†ΠΈΠΈ ΠΈΠ»ΠΈ сниТСниС Ρ†Π΅Π½Ρ‹ для ускорСния оборачиваСмости",
          expected_impact: "Π‘Π½ΠΈΠΆΠ΅Π½ΠΈΠ΅ остатков Π½Π° 30-50%"
        });
      }

      // ЦСновая оптимизация
      if (price && rating && parseFloat(rating.rating) > 4.5 && parseFloat(price.price) < parseFloat(price.old_price || "0") * 0.8) {
        recommendations.push({
          type: "pricing_optimization",
          priority: "high",
          offer_id: product.offer_id,
          action: "Π’ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒ ΠΏΠΎΠ²Ρ‹ΡˆΠ΅Π½ΠΈΡ Ρ†Π΅Π½Ρ‹ Π½Π° 10-15% ΠΏΡ€ΠΈ высоком Ρ€Π΅ΠΉΡ‚ΠΈΠ½Π³Π΅",
          expected_impact: "Π£Π²Π΅Π»ΠΈΡ‡Π΅Π½ΠΈΠ΅ ΠΌΠ°Ρ€ΠΆΠΈΠ½Π°Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ Π½Π° 10-15%"
        });
      }
    });

    return recommendations.sort((a, b) => {
      const priorityOrder = { "high": 3, "medium": 2, "low": 1 };
      return priorityOrder[b.priority] - priorityOrder[a.priority];
    });
  }
}

interface ProductInsightsReport {
  analysis_date: string;
  products_analyzed: number;
  ratings_analysis: RatingsAnalysis;
  inventory_analysis: InventoryAnalysis;
  pricing_analysis: PricingAnalysis;
  trends_analysis: TrendsAnalysis;
  cross_selling_opportunities: CrossSellingOpportunity[];
  actionable_recommendations: ActionableRecommendation[];
}

interface ActionableRecommendation {
  type: "quality_improvement" | "inventory_optimization" | "pricing_optimization" | "marketing_boost" | "cross_selling";
  priority: "high" | "medium" | "low";
  offer_id: string;
  action: string;
  expected_impact: string;
}

ΠžΠ±Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ошибок

try {
  const result = await productApi.importProducts({
    items: [productData]
  });
  
  // ΠžΡ‚ΡΠ»Π΅ΠΆΠΈΠ²Π°Π½ΠΈΠ΅ статуса ΠΈΠΌΠΏΠΎΡ€Ρ‚Π°
  const status = await productApi.getImportProductsInfo({
    task_id: result.task_id
  });
  
  status.result.forEach(item => {
    if (item.errors.length > 0) {
      console.error(`Ошибки для ${item.offer_id}:`, item.errors);
    }
  });
} catch (error) {
  if (error.response?.status === 400) {
    console.error("Ошибка Π²Π°Π»ΠΈΠ΄Π°Ρ†ΠΈΠΈ Π΄Π°Π½Π½Ρ‹Ρ…:", error.response.data);
  } else if (error.response?.status === 429) {
    console.error("ΠŸΡ€Π΅Π²Ρ‹ΡˆΠ΅Π½ Π»ΠΈΠΌΠΈΡ‚ запросов, ΠΏΠΎΠ²Ρ‚ΠΎΡ€ Ρ‡Π΅Ρ€Π΅Π· 60 сСкунд");
    await new Promise(resolve => setTimeout(resolve, 60000));
  } else {
    console.error("НСоТиданная ошибка:", error.message);
  }
}

Π›ΡƒΡ‡ΡˆΠΈΠ΅ ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠΈ

ΠžΠΏΡ‚ΠΈΠΌΠΈΠ·Π°Ρ†ΠΈΡ ΠΏΡ€ΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ

// Π‘Π°Ρ‚Ρ‡ΠΈΠ½Π³ запросов для Π±ΠΎΠ»ΡŒΡˆΠΈΡ… объСмов Π΄Π°Π½Π½Ρ‹Ρ…
async function batchProductOperations<T>(
  items: T[],
  operation: (batch: T[]) => Promise<any>,
  batchSize: number = 100
): Promise<any[]> {
  const results = [];
  
  for (let i = 0; i < items.length; i += batchSize) {
    const batch = items.slice(i, i + batchSize);
    const result = await operation(batch);
    results.push(result);
    
    // Rate limiting ΠΌΠ΅ΠΆΠ΄Ρƒ Π±Π°Ρ‚Ρ‡Π°ΠΌΠΈ
    if (i + batchSize < items.length) {
      await new Promise(resolve => setTimeout(resolve, 200));
    }
  }
  
  return results;
}

Π£ΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΆΠΈΠ·Π½Π΅Π½Π½Ρ‹ΠΌ Ρ†ΠΈΠΊΠ»ΠΎΠΌ Ρ‚ΠΎΠ²Π°Ρ€Π°

class ProductLifecycleManager {
  async createProduct(productData: ProductCreationData): Promise<string> {
    // 1. Π˜ΠΌΠΏΠΎΡ€Ρ‚ β†’ 2. Π˜Π·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΡ β†’ 3. Атрибуты β†’ 4. Активация
    const importResult = await this.api.importProducts({
      items: [productData.basicInfo]
    });
    
    await this.waitForImport(importResult.task_id);
    await this.addImages(productData.images);
    await this.setAttributes(productData.attributes);
    
    return productData.basicInfo.offer_id;
  }

  async retireProduct(offerId: string): Promise<void> {
    // 1. АрхивированиС β†’ 2. Анализ связанных β†’ 3. ΠžΡ‡ΠΈΡΡ‚ΠΊΠ°
    const productInfo = await this.api.getProductInfo({ offer_id: offerId });
    
    await this.api.archiveProducts({
      product_id: [productInfo.product_id]
    });
    
    // Анализ влияния Π½Π° связанныС Ρ‚ΠΎΠ²Π°Ρ€Ρ‹
    await this.analyzeRelatedImpact(productInfo.sku);
  }
}

Π˜Π½Ρ‚Π΅Π³Ρ€Π°Ρ†ΠΈΠΎΠ½Π½Ρ‹Π΅ Π·Π°ΠΌΠ΅Ρ‚ΠΊΠΈ

  • Rate Limiting: API ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ Π΄ΠΎ 1000 запросов Π² ΠΌΠΈΠ½ΡƒΡ‚Ρƒ
  • Batch Processing: РСкомСндуСтся ΠΎΠ±Ρ€Π°Π±Π°Ρ‚Ρ‹Π²Π°Ρ‚ΡŒ Ρ‚ΠΎΠ²Π°Ρ€Ρ‹ партиями ΠΏΠΎ 100 ΡˆΡ‚ΡƒΠΊ
  • Асинхронный ΠΈΠΌΠΏΠΎΡ€Ρ‚: Π˜ΠΌΠΏΠΎΡ€Ρ‚ Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ² выполняСтся асинхронно, трСбуСтся отслСТиваниС статуса
  • Π˜Π·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΡ: Π—Π°Π³Ρ€ΡƒΠ·ΠΊΠ° ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ выполняСтся ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ послС создания Ρ‚ΠΎΠ²Π°Ρ€Π°
  • Атрибуты: ΠšΡ€ΠΈΡ‚ΠΈΡ‡Π΅ΡΠΊΠΈ Π²Π°ΠΆΠ½Ρ‹ для ΠΌΠΎΠ΄Π΅Ρ€Π°Ρ†ΠΈΠΈ ΠΈ видимости Ρ‚ΠΎΠ²Π°Ρ€Π°
  • SKU связи: БистСма автоматичСски опрСдСляСт связанныС Ρ‚ΠΎΠ²Π°Ρ€Ρ‹ для кросс-ΠΏΡ€ΠΎΠ΄Π°ΠΆ
  • ΠšΠ²ΠΎΡ‚Ρ‹: Π‘ΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‚ Π»ΠΈΠΌΠΈΡ‚Ρ‹ Π½Π° Π·Π°Π³Ρ€ΡƒΠ·ΠΊΡƒ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ ΠΈ созданиС Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²