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

52
backend/test_wb_api.py Normal file
View File

@@ -0,0 +1,52 @@
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.wb_api import WildberriesAPI
from backend.wb_api.exceptions import WBAPIError
def test_wb_api():
# Load environment variables
env_path = os.path.join(os.path.dirname(__file__), '.env')
load_dotenv(env_path)
# Check if key is loaded
api_token = os.getenv('WB_API_TOKEN')
if not api_token:
print("Error: WB_API_TOKEN must be in backend/.env")
return
print("Initializing WildberriesAPI...")
api = WildberriesAPI()
try:
# Test 1: Get Content (Products)
print("\n--- Testing Content API (Products) ---")
cards_response = api.content.get_cards_list(limit=5)
print("Success! Response keys:", cards_response.keys())
cards = cards_response.get("cards", [])
print(f"Found {len(cards)} products.")
if cards:
nm_id = cards[0].get("nmID")
vendor_code = cards[0].get("vendorCode")
print(f"First product - nmID: {nm_id}, Vendor Code: {vendor_code}")
# Test 2: Get Marketplace (Orders)
print("\n--- Testing Marketplace API (New Orders) ---")
orders_response = api.marketplace.get_new_orders()
orders = orders_response.get("orders", [])
print(f"Found {len(orders)} new FBS orders.")
except WBAPIError as e:
print(f"API Error: {e}")
except Exception as e:
print(f"Unexpected Error: {e}")
if __name__ == '__main__':
test_wb_api()