feat: implement backend API clients for multi-marketplace integration and frontend service layer

This commit is contained in:
2026-05-12 13:16:14 +03:00
parent 6974af486a
commit ee39a3d83b
65 changed files with 2501 additions and 33 deletions

54
backend/test_ozon_api.py Normal file
View File

@@ -0,0 +1,54 @@
import os
import sys
from dotenv import load_dotenv
# Add parent dir to path so we can import backend packages
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from backend.ozon_api import OzonAPI
from backend.ozon_api.exceptions import OzonAPIError
def test_ozon_api():
# Load environment variables
env_path = os.path.join(os.path.dirname(__file__), '.env')
load_dotenv(env_path)
# Check if keys are loaded
client_id = os.getenv('OZON_CLIENT_ID')
api_key = os.getenv('OZON_API_KEY')
if not client_id or not api_key:
print("Error: OZON_CLIENT_ID and OZON_API_KEY must be in backend/.env")
return
print(f"Initializing OzonAPI with Client-ID: {client_id}")
api = OzonAPI()
try:
# Test 1: Get products
print("\n--- Testing Products ---")
products_response = api.products.get_list(limit=5)
print("Success! Response keys:", products_response.keys())
# Ozon wraps responses in 'result'
result = products_response.get("result", {})
items = result.get("items", [])
print(f"Found {len(items)} products.")
if items:
product_id = items[0].get("product_id")
offer_id = items[0].get("offer_id")
print(f"First product - Product ID: {product_id}, Offer ID: {offer_id}")
# Test 2: Get specific product info
print("\n--- Testing Product Info ---")
info = api.products.get_info(product_id=product_id)
print("Product Info Name:", info.get("result", {}).get("name", "Unknown"))
except OzonAPIError as e:
print(f"API Error: {e}")
except Exception as e:
print(f"Unexpected Error: {e}")
if __name__ == '__main__':
test_ozon_api()