Skip to content

methods

OrderMethods

Bases: MarketApiABCMethods

get_label async

Python
1
get_label(order_id: int, format_: PageFormatType | None = None) -> bytes

Get all labels for order in specified format. :param order_id: order id. :param format_: pdf file format. Defaults to A6

:return: PDF-file with all labels

Source code in marketplace_apis/yandex/order/methods.py
Python
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
async def get_label(
    self, order_id: int, format_: PageFormatType | None = None
) -> bytes:
    """Get all labels for order in specified format.
    :param order_id: order id.
    :param format_: pdf file format. Defaults to A6

    :return: PDF-file with all labels"""
    _, data = await self.client.get(
        self._requester.build_campaign_url(
            f"orders/{order_id}/{API_PATH["get_delivery_labels"]}"
        ),
        params={"format": format_},
        decode=False,
    )
    return data

list_orders async

Python
1
list_orders(iter_: bool = True, page_size: int = 50, page: int = 1, **kwargs: Unpack[ListOrders]) -> list[Order]

List orders. :param page_size: Maximum amount of orders what will be retrieved in one request :param page: page from that order will be retrieved :param iter_: Whenever to get all postings by making multiple requests or not

:return: List of orders

Source code in marketplace_apis/yandex/order/methods.py
Python
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
async def list_orders(
    self,
    iter_: bool = True,
    page_size: int = 50,
    page: int = 1,
    **kwargs: Unpack[ListOrders],
) -> list[Order]:
    """List orders.
    :param page_size: Maximum amount of orders what will be retrieved in one request
    :param page: page from that order will be retrieved
    :param iter_: Whenever to get all postings by making multiple requests or not

    :return: List of orders
    """
    raw_orders = []
    if kwargs is None:
        kwargs = {}
    dict_datetime_to_iso(kwargs, tz=UTC3Timezone())
    url = self.client.build_campaign_url(API_PATH["list_orders"])

    async def make_request(page):
        resp, decoded_resp = await self.client.get(
            url, params={"pageSize": page_size, "page": page, **kwargs}
        )
        nonlocal raw_orders
        raw_orders += decoded_resp["orders"]
        return resp, decoded_resp

    _, data = await make_request(page)
    tasks = []
    while iter_ and data["pager"]["pagesCount"] != data["pager"]["currentPage"]:
        page += 1
        tasks.append(make_request(page))

    # Run all tasks concurrently
    await asyncio.gather(*tasks)

    return [Order.from_dict(raw_order) for raw_order in raw_orders]

update_status async

Python
1
update_status(order_id: int, status: OrderStatusType, substatus: OrderSubstatusType | None = None) -> Order

Update status of order. :param order_id: order id. :param status: new status :param substatus: new substatus

:return: updated order

Source code in marketplace_apis/yandex/order/methods.py
Python
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
async def update_status(
    self,
    order_id: int,
    status: OrderStatusType,
    substatus: OrderSubstatusType | None = None,
) -> Order:
    """Update status of order.
    :param order_id: order id.
    :param status: new status
    :param substatus: new substatus

    :return: updated order"""
    order_status_data = {"status": status}
    if substatus:
        order_status_data["substatus"] = substatus
    _, data = await self.client.put(
        self.client.build_campaign_url(
            f"orders/{order_id}/{API_PATH["order_status"]}"
        ),
        data={"order": order_status_data},
    )
    return Order.from_dict(data["order"])