40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
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)
|