feat: implement backend API clients for multi-marketplace integration and frontend service layer
This commit is contained in:
39
backend/wb_api/services/content.py
Normal file
39
backend/wb_api/services/content.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from typing import Dict, Any, List
|
||||
from ..client import WBClient
|
||||
|
||||
class ContentService:
|
||||
"""Service to handle WB product cards (Content API)."""
|
||||
|
||||
def __init__(self, client: WBClient):
|
||||
self.client = client
|
||||
self.base_url = WBClient.CONTENT_API
|
||||
|
||||
def get_cards_list(self, limit: int = 100, updated_at: str = "", last_id: str = "") -> Dict[str, Any]:
|
||||
"""
|
||||
Get list of nomenclatures (product cards).
|
||||
Endpoint: /content/v2/get/cards/list
|
||||
"""
|
||||
payload = {
|
||||
"settings": {
|
||||
"cursor": {
|
||||
"limit": limit
|
||||
},
|
||||
"filter": {
|
||||
"withPhoto": -1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if updated_at:
|
||||
payload["settings"]["cursor"]["updatedAt"] = updated_at
|
||||
if last_id:
|
||||
payload["settings"]["cursor"]["nmID"] = int(last_id)
|
||||
|
||||
return self.client.post(self.base_url, "/content/v2/get/cards/list", data=payload)
|
||||
|
||||
def create_cards(self, cards: List[Dict[str, Any]]) -> Dict[str, Any]:
|
||||
"""
|
||||
Create product cards.
|
||||
Endpoint: /content/v2/cards/upload
|
||||
"""
|
||||
return self.client.post(self.base_url, "/content/v2/cards/upload", data=cards)
|
||||
Reference in New Issue
Block a user