test
This commit is contained in:
1 parent
187bf1c111
commit
8c11958d95
1 file changed
+9
-9
+9
-9
@@ -64,15 +64,15 @@ async def get_item_by_id(item_id: str) -> dict:
|
|||||||
Exception: If item not found or API error
|
Exception: If item not found or API error
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
result = await client.catalog.retrieve_catalog_object(
|
result = await client.catalog.batch_retrieve_catalog_objects(
|
||||||
object_id=item_id, include_related_objects=True
|
body={"object_ids": [item_id], "include_related_objects": True}
|
||||||
)
|
)
|
||||||
result_json = json.loads(result.model_dump_json())
|
result_json = json.loads(result.model_dump_json())
|
||||||
|
|
||||||
if not result_json.get("object"):
|
if not result_json.get("objects"):
|
||||||
raise ValueError(f"Item {item_id} not found")
|
raise ValueError(f"Item {item_id} not found")
|
||||||
|
|
||||||
obj = result_json["object"]
|
obj = result_json["objects"][0]
|
||||||
item_data = obj.get("item_data", {})
|
item_data = obj.get("item_data", {})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -107,16 +107,16 @@ async def get_item_by_variation_id(variation_id: str) -> dict:
|
|||||||
Exception: If variation/item not found or API error
|
Exception: If variation/item not found or API error
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Get variation object
|
# Get variation object using batch_retrieve
|
||||||
result = await client.catalog.retrieve_catalog_object(
|
result = await client.catalog.batch_retrieve_catalog_objects(
|
||||||
object_id=variation_id, include_related_objects=True
|
body={"object_ids": [variation_id], "include_related_objects": True}
|
||||||
)
|
)
|
||||||
result_json = json.loads(result.model_dump_json())
|
result_json = json.loads(result.model_dump_json())
|
||||||
|
|
||||||
if not result_json.get("object"):
|
if not result_json.get("objects"):
|
||||||
raise ValueError(f"Variation {variation_id} not found")
|
raise ValueError(f"Variation {variation_id} not found")
|
||||||
|
|
||||||
variation_obj = result_json["object"]
|
variation_obj = result_json["objects"][0]
|
||||||
|
|
||||||
# Get parent item ID from variation
|
# Get parent item ID from variation
|
||||||
item_id = variation_obj.get("item_variation_data", {}).get("item_id")
|
item_id = variation_obj.get("item_variation_data", {}).get("item_id")
|
||||||
|
|||||||
Reference in new issue
Block a user