Skip to content

methods

CampaignMethods

Bases: MarketApiABCMethods

list_campaigns async

Python
1
list_campaigns(iter_: bool = True, page_size: int = 50, page: int = 1) -> list[Campaign]

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

:return: List of campaigns

Source code in marketplace_apis/yandex/campaign/methods.py
Python
24
25
26
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
async def list_campaigns(
    self,
    iter_: bool = True,
    page_size: int = 50,
    page: int = 1,
) -> list[Campaign]:
    """List campaigns.
    :param page_size: Maximum amount of campaigns what will be retrieved in one
    request
    :param page: page from that campaigns will be retrieved
    :param iter_: Whenever to get all postings by making multiple requests or not

    :return: List of campaigns
    """
    raw_campaigns = []

    async def make_request():
        resp, decoded_resp = await self.client.get(
            API_PATH["list_campaigns"], params={"pageSize": page_size, "page": page}
        )
        nonlocal raw_campaigns
        raw_campaigns += decoded_resp["campaigns"]
        return resp, decoded_resp

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

    return [Campaign.from_dict(raw_campaign) for raw_campaign in raw_campaigns]