Π£ΠΏΡΠ°Π²Π»Π΅Π½ΠΈΠ΅ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΡΠΌΠΈ ΠΈ Ρ Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊΠ°ΠΌΠΈ ΡΠΎΠ²Π°ΡΠΎΠ² OZON
ΠΠΎΠ»Π½ΠΎΠ΅ Π΄Π΅ΡΠ΅Π²ΠΎ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΉ ΠΈ ΡΠΈΠΏΠΎΠ² ΡΠΎΠ²Π°ΡΠΎΠ²
/v1/description-category/tree
Π₯Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊΠΈ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ
/v1/description-category/attribute
ΠΠ½Π°ΡΠ΅Π½ΠΈΡ Ρ Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊΠΈ Ρ ΠΏΠ°Π³ΠΈΠ½Π°ΡΠΈΠ΅ΠΉ
/v1/description-category/attribute/values
ΠΠΎΠΈΡΠΊ Π·Π½Π°ΡΠ΅Π½ΠΈΠΉ Ρ Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊΠΈ
/v1/description-category/attribute/values/search
ΠΠ°Π³ΡΡΠ·ΠΈΡΡ ΠΏΠΎΠ»Π½ΡΡ ΡΡΡΡΠΊΡΡΡΡ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΉ OZON
ΠΡΠ±ΡΠ°ΡΡ ΠΊΠΎΠ½Π΅ΡΠ½ΡΡ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΡ Π΄Π»Ρ ΡΠΎΠ²Π°ΡΠ°
ΠΠ·ΡΡΠΈΡΡ Ρ Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊΠΈ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ
ΠΡΠΎΠ²Π΅ΡΠΈΡΡ ΠΎΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΡΠ΅ ΠΏΠΎΠ»Ρ
import { OzonSellerAPI } from 'daytona-ozon-seller-api';
const client = new OzonSellerAPI({
clientId: 'your-client-id',
apiKey: 'your-api-key'
});
// ΠΠ°Π·ΠΎΠ²ΡΠΉ workflow ΡΠ°Π±ΠΎΡΡ Ρ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΡΠΌΠΈ
try {
// 1. ΠΠΎΠ»ΡΡΠΈΡΡ Π΄Π΅ΡΠ΅Π²ΠΎ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΉ
const categoryTree = await client.category.getCategoryTree({
language: 'RU'
});
console.log('π³ ΠΠ΅ΡΠ΅Π²ΠΎ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΉ Π·Π°Π³ΡΡΠΆΠ΅Π½ΠΎ');
// 2. ΠΠ°ΠΉΡΠΈ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ Π΄Π»Ρ ΡΠΎΠ·Π΄Π°Π½ΠΈΡ ΡΠΎΠ²Π°ΡΠΎΠ² (ΠΊΠΎΠ½Π΅ΡΠ½ΡΠ΅ ΡΠ·Π»Ρ)
const findLeafCategories = (items: any[]): any[] => {
const leafCategories: any[] = [];
items.forEach(item => {
if ((!item.children || item.children.length === 0) && !item.disabled) {
leafCategories.push(item);
} else if (item.children) {
leafCategories.push(...findLeafCategories(item.children));
}
});
return leafCategories;
};
const leafCategories = findLeafCategories(categoryTree.result || []);
console.log(`π ΠΠΎΡΡΡΠΏΠ½ΠΎ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΉ Π΄Π»Ρ ΡΠΎΠ·Π΄Π°Π½ΠΈΡ ΡΠΎΠ²Π°ΡΠΎΠ²: ${leafCategories.length}`);
if (leafCategories.length > 0) {
const selectedCategory = leafCategories[0];
console.log(`\nπ― ΠΡΠ±ΡΠ°Π½Π° ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΡ: ${selectedCategory.category_name}`);
console.log(` ID ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ: ${selectedCategory.description_category_id}`);
console.log(` ID ΡΠΈΠΏΠ°: ${selectedCategory.type_id}`);
// 3. ΠΠΎΠ»ΡΡΠΈΡΡ Ρ
Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊΠΈ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ
const attributes = await client.category.getCategoryAttributes({
description_category_id: selectedCategory.description_category_id,
type_id: selectedCategory.type_id,
language: 'RU'
});
console.log(`\nπ Π₯Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊ Π² ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ: ${attributes.result?.length || 0}`);
// 4. ΠΠ°ΠΉΡΠΈ Ρ
Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊΠΈ ΡΠΎ ΡΠΏΡΠ°Π²ΠΎΡΠ½ΠΈΠΊΠ°ΠΌΠΈ Π·Π½Π°ΡΠ΅Π½ΠΈΠΉ
const dictionaryAttributes = attributes.result?.filter(attr =>
attr.dictionary_id && attr.dictionary_id > 0
) || [];
console.log(`π Π₯Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊ ΡΠΎ ΡΠΏΡΠ°Π²ΠΎΡΠ½ΠΈΠΊΠ°ΠΌΠΈ: ${dictionaryAttributes.length}`);
}
} catch (error) {
console.error('β ΠΡΠΈΠ±ΠΊΠ° ΡΠ°Π±ΠΎΡΡ Ρ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΡΠΌΠΈ:', error);
}
Π₯Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊΠΈ, ΠΊΠΎΡΠΎΡΡΠ΅ Π΄ΠΎΠ»ΠΆΠ½Ρ Π±ΡΡΡ Π·Π°ΠΏΠΎΠ»Π½Π΅Π½Ρ ΠΏΡΠΈ ΡΠΎΠ·Π΄Π°Π½ΠΈΠΈ ΡΠΎΠ²Π°ΡΠ°. ΠΡΠΌΠ΅ΡΠ΅Π½Ρ ΡΠ»Π°Π³ΠΎΠΌ is_required: true
Π₯Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊΠΈ Ρ ΠΏΡΠ΅Π΄ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½Π½ΡΠΌΠΈ Π·Π½Π°ΡΠ΅Π½ΠΈΡΠΌΠΈ. dictionary_id > 0
ΡΠΊΠ°Π·ΡΠ²Π°Π΅Ρ Π½Π° Π½Π°Π»ΠΈΡΠΈΠ΅ ΡΠΏΡΠ°Π²ΠΎΡΠ½ΠΈΠΊΠ°
ΠΡΠΏΠΎΠ»ΡΠ·ΡΡΡΡΡ Π΄Π»Ρ ΡΠΈΠ»ΡΡΡΠ°ΡΠΈΠΈ ΡΠΎΠ²Π°ΡΠΎΠ² Π½Π° ΡΠ°ΠΉΡΠ΅. ΠΡΠΌΠ΅ΡΠ΅Π½Ρ ΡΠ»Π°Π³ΠΎΠΌ is_aspect: true
ΠΠΎΠ³ΡΡ ΡΠΎΠ΄Π΅ΡΠΆΠ°ΡΡ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ Π·Π½Π°ΡΠ΅Π½ΠΈΠΉ ΠΎΠ΄Π½ΠΎΠ²ΡΠ΅ΠΌΠ΅Π½Π½ΠΎ. is_collection: true
// ΠΠ½Π°Π»ΠΈΠ· Ρ
Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ
const analyzeCategoryAttributes = async (categoryId: number, typeId: number) => {
try {
const attributes = await client.category.getCategoryAttributes({
description_category_id: categoryId,
type_id: typeId,
language: 'RU'
});
const analysis = {
total: attributes.result?.length || 0,
required: 0,
optional: 0,
collections: 0,
aspects: 0,
withDictionary: 0,
withoutDictionary: 0,
groups: new Set()
};
const requiredAttributes: any[] = [];
const dictionaryAttributes: any[] = [];
attributes.result?.forEach(attr => {
// ΠΠ°Π·ΠΎΠ²Π°Ρ ΡΡΠ°ΡΠΈΡΡΠΈΠΊΠ°
if (attr.is_required) {
analysis.required++;
requiredAttributes.push(attr);
} else {
analysis.optional++;
}
if (attr.is_collection) analysis.collections++;
if (attr.is_aspect) analysis.aspects++;
// Π‘ΠΏΡΠ°Π²ΠΎΡΠ½ΠΈΠΊΠΈ
if (attr.dictionary_id && attr.dictionary_id > 0) {
analysis.withDictionary++;
dictionaryAttributes.push(attr);
} else {
analysis.withoutDictionary++;
}
// ΠΡΡΠΏΠΏΡ
if (attr.group_name) {
analysis.groups.add(attr.group_name);
}
});
console.log('π ΠΠ½Π°Π»ΠΈΠ· Ρ
Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ:');
console.log(` ΠΡΠ΅Π³ΠΎ Ρ
Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊ: ${analysis.total}`);
console.log(` ΠΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΡΡ
: ${analysis.required}`);
console.log(` ΠΠ΅ΠΎΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΡΡ
: ${analysis.optional}`);
console.log(` Π‘ΠΎ ΡΠΏΡΠ°Π²ΠΎΡΠ½ΠΈΠΊΠΎΠΌ: ${analysis.withDictionary}`);
console.log(` ΠΡΡΠΏΠΏ Ρ
Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊ: ${analysis.groups.size}`);
return { analysis, requiredAttributes, dictionaryAttributes };
} catch (error) {
console.error('β ΠΡΠΈΠ±ΠΊΠ° Π°Π½Π°Π»ΠΈΠ·Π° Ρ
Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊ:', error);
}
};
// ΠΠ°Π»ΠΈΠ΄Π°ΡΠΈΡ ΡΠΎΠ²Π°ΡΠ° ΠΏΠΎ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ
const validateProductForCategory = async (categoryId: number, typeId: number, productData: any) => {
try {
const attributes = await client.category.getCategoryAttributes({
description_category_id: categoryId,
type_id: typeId,
language: 'RU'
});
const requiredAttributes = attributes.result?.filter(attr => attr.is_required) || [];
const errors: string[] = [];
const warnings: string[] = [];
console.log(`π ΠΠ°Π»ΠΈΠ΄Π°ΡΠΈΡ ΡΠΎΠ²Π°ΡΠ° Π΄Π»Ρ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ ${categoryId}...`);
// ΠΡΠΎΠ²Π΅ΡΠΊΠ° ΠΎΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΡΡ
Ρ
Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊ
for (const attr of requiredAttributes) {
const value = productData[attr.name] || productData[attr.id];
if (!value) {
errors.push(`ΠΡΡΡΡΡΡΠ²ΡΠ΅Ρ ΠΎΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½Π°Ρ Ρ
Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊΠ°: ${attr.name}`);
} else if (attr.dictionary_id && attr.dictionary_id > 0) {
// ΠΡΠΎΠ²Π΅ΡΠΊΠ° Π·Π½Π°ΡΠ΅Π½ΠΈΡ ΠΈΠ· ΡΠΏΡΠ°Π²ΠΎΡΠ½ΠΈΠΊΠ°
try {
const searchResult = await client.category.searchCategoryAttributeValues({
attribute_id: attr.id,
description_category_id: categoryId,
type_id: typeId,
value: value.toString(),
limit: 1
});
const exactMatch = searchResult.result?.find(v =>
v.value?.toLowerCase() === value.toString().toLowerCase()
);
if (!exactMatch) {
warnings.push(`ΠΠ½Π°ΡΠ΅Π½ΠΈΠ΅ "${value}" Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½ΠΎ Π² ΡΠΏΡΠ°Π²ΠΎΡΠ½ΠΈΠΊΠ΅ Π΄Π»Ρ "${attr.name}"`);
}
} catch (error) {
warnings.push(`ΠΠ΅ ΡΠ΄Π°Π»ΠΎΡΡ ΠΏΡΠΎΠ²Π΅ΡΠΈΡΡ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ Π΄Π»Ρ "${attr.name}"`);
}
}
}
const isValid = errors.length === 0;
console.log(`${isValid ? 'β
' : 'β'} ΠΠ°Π»ΠΈΠ΄Π°ΡΠΈΡ Π·Π°Π²Π΅ΡΡΠ΅Π½Π°:`);
console.log(` ΠΡΠΈΠ±ΠΎΠΊ: ${errors.length}`);
console.log(` ΠΡΠ΅Π΄ΡΠΏΡΠ΅ΠΆΠ΄Π΅Π½ΠΈΠΉ: ${warnings.length}`);
return { isValid, errors, warnings, requiredAttributesCount: requiredAttributes.length };
} catch (error) {
console.error('β ΠΡΠΈΠ±ΠΊΠ° Π²Π°Π»ΠΈΠ΄Π°ΡΠΈΠΈ ΡΠΎΠ²Π°ΡΠ°:', error);
return {
isValid: false,
errors: [`ΠΡΠΈΠ±ΠΊΠ° Π²Π°Π»ΠΈΠ΄Π°ΡΠΈΠΈ: ${error.message}`],
warnings: [],
requiredAttributesCount: 0
};
}
};
disabled
dictionary_id > 0
last_value_id