Yandex Direct Api Wrapper (yandex direct api v5)
Installation
Instal user pip
...
pip install yandex-direct-api
Usage
from direct_api import DirectAPI
client = DirectAPI('<access_token>', '<clid>', lang='ru')
AgencyClient:add
name | type | default value |
---|
login | str | *required |
first_name | str | *required |
last_name | str | *required |
currency | str | *required |
grants | list | None |
notification | dict | None |
settings | dict | None |
result = client.AgencyClient.add(login='<login>', first_name='<fname>', last_name='<lname>', currency='RUB')
AgencyClient:get
name | type | default value |
---|
field_names | list | *required |
limit | int | 500 |
offset | int | 0 |
logins | list | None |
archived | str | None |
result = client.AgencyClient.get(field_names=["ClientId", "ClientInfo"])
AgencyClient:update
name | type | default value |
---|
clients | list | *required |
clients = [{
"ClientId": 1
"ClientInfo": 'client info',
},
]
result = client.AgencyClient.update(clients=clients)
AdExtension:add
name | type | default value |
---|
ad_extensions | list | *required |
ad_extendsions = [{
"Callout": {"CalloutText": "<callout text>"},
},
]
result = client.AdExtension.add(ad_extendsions=ad_extendsions)
AdExtension:delete
name | type | default value |
---|
ids | list | *required |
ids = ['1', '2', '3']
result = client.AdExtension.delete(ids)
AdExtension:get
name | type | default value |
---|
field_names | list | *required |
ids | list | None |
types | list | None |
statuses | list | None |
modify_since | str | None |
callout_field_names | list | None |
limit | int | 500 |
offset | int | 0 |
field_names = ['Id', 'Type', 'Status']
result = client.AdExtension.get(field_names)
AdGroup:add
name | type | default value |
---|
ad_groups | list | *required |
ad_groups = [{'Name': 'Test', 'CampaignId': '123', 'RegionIds'}]
result = client.AdGroup.add(ad_groups)
AdGroup:delete
name | type | default value |
---|
ids | list | *required |
ids = ['123', '124', '125']
result = client.AdGroup.get(ids=ids)
AdGroup:get
name | type | default value |
---|
field_names | list | *required |
ids | list | None |
campaign_ids | list | None |
types | list | None |
statuses | list | None |
serving_statuses | list | None |
app_icon_statuses | list | None |
negative_keyword_shared_set_ids | list | None |
mobile_app_ad_group_field_names | list | None |
dynamic_text_ad_group_field_names | list | None |
dynamic_text_feed_ad_group_field_names | list | None |
limit | int | 500 |
offset | int | 500 |
field_names = ['AdGroupId', 'Name', 'CampaignId']
result = client.AdGroup.get(field_names=field_names)
AdGroup:update
name | type | default value |
---|
ad_groups | list | *required |
ad_groups = [{'Name': 'Test', 'CampaignId': '123', 'RegionIds', 'AdGroupId': '123'}]
result = client.AdGroup.update(ad_groups)
AdImage:add
name | type | default value |
---|
ad_images | list | *required |
ad_images = [{'Name': 'Test', 'ImageData': '<binary>'}]
result = client.AdImage.add(ad_images)
AdImage:delete
name | type | default value |
---|
hashes | list | *required |
hashes = ['<hash1>', '<hash2>']
result = client.AdImage.delete(hashes)
AdImage:get
name | type | default value |
---|
field_names | list | *required |
ad_images_hashes | list | None |
associated | str | None |
limit | init | 500 |
offset | init | 0 |
field_names = ['AdImageHash', 'Name']
result = client.AdImage.get(field_names)
Ad:add
name | type | default value |
---|
ads | list | *required |
ads = [{'AdgroupId': '<id>', 'TextAd': {}}]
result = client.Ad.add(ads)
Ad:archive
name | type | default value |
---|
ids | list | *required |
ids = ['123', '124']
result = client.Ad.archive(ids)
Ad:delete
name | type | default value |
---|
ids | list | *required |
ids = ['123', '124']
result = client.Ad.delete(ids)
Ad:get
name | type | default value |
---|
field_names | list | *required |
ids | list | None |
campaign_ids | list | None |
ad_group_ids | list | None |
states | list | None |
statuses | list | None |
types | list | None |
mobile | str | None |
v_card_ids | list | None |
sitelink_set_ids | list | None |
ad_image_hashes | list | None |
v_card_moderation_statuses | list | None |
sitelink_moderation_statuses | list | None |
ad_image_moderation_statuses | list | None |
ad_extension_ids | list | None |
text_ad_field_names | list | None |
text_ad_price_extension_field_names | list | None |
mobile_app_field_names | list | None |
dynamic_text_ad_field_names | list | None |
mobile_app_image_ad_field_names | list | None |
text_ad_builder_ad_field_names | list | None |
mobile_app_ad_builder_ad_field_names | list | None |
cpc_video_ad_builder_ad_field_names | list | None |
cpm_banner_ad_builder_ad_field_names | list | None |
cpm_video_ad_builder_ad_field_names | list | None |
limit | int | 500 |
offset | int | 0 |
field_names = ['Id', 'CampaignId']
result = client.Ad.get(field_names)
Ad:moderate
name | type | default value |
---|
ids | list | *required |
ids = ['123', '124']
result = client.Ad.moderate(ids)
Ad:resume
name | type | default value |
---|
ids | list | *required |
ids = ['123', '124']
result = client.Ad.resume(ids)
Ad:suspend
name | type | default value |
---|
ids | list | *required |
ids = ['123', '124']
result = client.Ad.suspend(ids)
Ad:unarchive
name | type | default value |
---|
ids | list | *required |
ids = ['123', '124']
result = client.Ad.unarchive(ids)
Ad:update
name | type | default value |
---|
ads | list | *required |
ads = [{'AdgroupId': '<id>', 'TextAd': {}, 'Id': '<Id>'}]
result = client.Ad.update(ads)
AudienceTarget:add
name | type | default value |
---|
ads | list | *required |
ads = [{'AdgroupId': '<id>', }]
result = client.AudienceTarget.add(ids)
AudienceTarget:delete
name | type | default value |
---|
ids | list | *required |
ids = ['232324353']
result = client.AudienceTarget.delete(ids)
AudienceTarget:get_audience_targets
name | type | default value |
---|
field_names | list | *required |
ids | list | None |
ad_group_ids | list | None |
campaign_ids | list | None |
retargeting_list_ids | list | None |
interest_ids | list | None |
states | list | None |
limit | int | 500 |
offset | int | 0 |
field_names = ['Id']
result = client.AudienceTarget.get_audience_targets(field_names, campaigns_ids=[123])
AudienceTarget:resume
name | type | default value |
---|
ids | list | *required |
ids = ['232324353']
result = client.AudienceTarget.resume(ids)
AudienceTarget:set_bids
name | type | default value |
---|
bids | list | *required |
bids = [{'Id': '<id>', 'AdGroupId': '<Id>'}]
result = client.AudienceTarget.set_bids(bids)
Bid:get
name | type | default value |
---|
field_names | list | *required |
keyword_ids | list | None |
ad_group_ids | list | None |
campaign_ids | list | None |
serving_statuses | list | None |
limit | int | 500 |
offset | int | 0 |
field_names = ['Id']
result = client.Bid.suspend(field_names, campaign_ids=[1232424532])
Bid:set
name | type | default value |
---|
bids | list | *required |
bids = [{'Bid': '<long>'}]
result = client.Bid.set(bids)
Bid:set_auto
name | type | default value |
---|
bids | list | *required |
bids = [{'CampaignID': '<long>', 'Scope': 'SEARCH'}]
result = client.Bid.set_auto(bids)
BidsModifier:add
name | type | default value |
---|
bid_modifiers | list | *required |
bid_modifiers = [{'MobileAdjustment': {'BidModifier': '<id>'}}]
result = client.BidsModifier.add(bid_modifiers)
BidsModifier:delete
name | type | default value |
---|
ids | list | *required |
ids = ['1312324343']
result = client.BidsModifier.delete(ids)
BidsModifier:get
name | type | default value |
---|
field_names | list | *required |
ids | list | None |
campaign_ids | list | None |
ad_group_ids | list | None |
types | list | None |
levels | list | None |
mobile_adjustment_field_names | list | None |
desktop_adjustment_field_names | list | None |
demographics_adjustment_field_names | list | None |
retargeting_adjustment_field_names | list | None |
regional_adjustment_field_names | list | None |
video_adjustment_field_names | list | None |
limit | list | 500 |
offset | list | 0 |
field_names = ['Id', 'CampaignId', 'Type']
result = client.BidsModifier.get(field_names, campaign_ids=['123453534'])
BidsModifier:set
name | type | default value |
---|
bid_modifiers | list | *required |
ids = [{'Id': '<id>', 'BidModifier': 124242}]
result = client.BidsModifier.set(bid_modifiers)
BidsModifier:toggle
name | type | default value |
---|
bid_modifier_toggle_items | list | *required |
bid_modifier_toggle_items = [{'CampaignId': '<id>', 'Type': "DEMOGRAPHICS_ADJUSTMENT","Enabled": "YES"}]
result = client.BidsModifier.toggle(bid_modifier_toggle_items)
Campaign:add
name | type | default value |
---|
campaigns | list | *required |
campaign_item = {}
campaigns = [campaign_item]
result = client.Campaign.add(campaigns)
Campaign:archive
name | type | default value |
---|
ids | list | *required |
ids = ['12312535', '345345345', '23432325345']
result = client.Campaign.archive(ids)
Campaign:delete
name | type | default value |
---|
ids | list | *required |
ids = ['12312535', '345345345', '23432325345']
result = client.Campaign.delete(ids)
Campaign:get
name | type | default value |
---|
field_names | list | *required |
ids | list | None |
types | list | None |
states | list | None |
statuses | list | None |
statuses_payments | list | None |
text_campaign_field_names | list | None |
mobile_app_campaign_field_names | list | None |
dynamic_text_campaign_field_names | list | None |
cpm_banner_campaign_field_names | list | None |
limit | int | 500 |
offset | int | 0 |
field_names = ['Id', 'Name', 'Type']
result = client.Campaign.get(field_names=field_names)
Campaign:resume
name | type | default value |
---|
ids | list | *required |
ids = ['12312535', '345345345', '23432325345']
result = client.Campaign.resume(ids)
Campaign:suspend
name | type | default value |
---|
ids | list | *required |
ids = ['12312535', '345345345', '23432325345']
result = client.Campaign.suspend(ids)
Campaign:unarchive
name | type | default value |
---|
ids | list | *required |
ids = ['12312535', '345345345', '23432325345']
result = client.Campaign.unarchive(ids)
Campaign:update
name | type | default value |
---|
campaigns | list | *required |
campaigns = [{'Id': '12312535','Name': 'updated!']
result = client.Campaign.unarchive(campaigns)
Change:check_dictionaries
name | type | default value |
---|
timestamp | int | *required |
from time import time
timestamp = int(time.now()- 1800)
result = client.Change.check_dictionaries(timestamp)
Change:check_campaigns
name | type | default value |
---|
timestamp | int | *required |
from time import time
timestamp = int(time.now()- 1800)
result = client.Change.check_campaigns(timestamp)
Change:check
name | type | default value |
---|
timestamp | int | *required |
field_names | list | *required |
campaign_ids | list | None |
ad_group_ids | list | None |
ad_ids | list | None |
from time import time
timestamp = int(time.now()- 1800)
field_names = ['Id', 'Name']
result = client.Change.check(timestamp, fiel_names)
Creative:get
name | type | default value |
---|
field_names | list | *required |
ids | list | None |
types | list | None |
video_extension_creative_field_names | list | None |
cpc_video_creative_field_names | list | None |
cpm_video_creative_field_names | list | None |
limit | int | 10000 |
offset | int | 0 |
field_names = ['Id', 'Name', 'Type', 'PreviewUrl']
result = client.Creative.get(field_names)
Dictionary:get
name | type | default value |
---|
dictionary_names | list | *required |
dictionary_names = ['TimeZones', 'Currencies']
result = client.Dictionary.get(dictionary_names)
DynamicTextAdTarget:add
name | type | default value |
---|
webpages | list | *required |
bid | list | None |
context_bid | str | None |
context_bid | str | None |
strategy_priority | str | None |
webpages = [{'Name': 'Test', 'AdGroupId': '123242453253'}]
result = client.DynamicTextAdTarget.add(webpages)
DynamicTextAdTarget:delete
name | type | default value |
---|
ids | list | *required |
ids = ['213232432432']
result = client.DynamicTextAdTarget.delete(ids)
DynamicTextAdTarget:get
name | type | default value |
---|
field_names | list | *required |
ids | list | None |
ad_group_ids | list | None |
campaign_ids | list | None |
states | list | None |
limit | int | 10000 |
offset | int | 0 |
ids = ['AdGroupId', 'Bid']
result = client.DynamicTextAdTarget.get(ids)
DynamicTextAdTarget:resume
name | type | default value |
---|
ids | list | *required |
ids = ['213232432432']
result = client.DynamicTextAdTarget.resume(ids)
DynamicTextAdTarget:suspend
name | type | default value |
---|
ids | list | *required |
ids = ['213232432432']
result = client.DynamicTextAdTarget.suspend(ids)
DynamicTextAdTarget:set_bids
name | type | default value |
---|
bids | list | *required |
set_bit_item = {}
bids = [set_bit_item]
result = client.DynamicTextAdTarget.set_bids(bids)
KeywordBid:get
name | type | default value |
---|
field_names | list | *required |
campaign_ids | list | None |
ad_group_ids | list | None |
keyword_ids | list | None |
serving_statuses | list | None |
search_field_names | list | None |
network_field_names | list | None |
limit | int | 10000 |
offset | int | 0 |
field_names = ['Id']
campaign_ids = ['123123212353']
result = client.KeywordBid.get(field_names, campaign_ids=campaign_ids)
KeywordBid:set
name | type | default value |
---|
keyword_bids | list | *required |
set_bit_item = {}
keyword_bids = [set_bit_item]
result = client.KeywordBid.set(keyword_bids)
KeywordBid:set_auto
name | type | default value |
---|
keyword_bids | list | *required |
set_bit_item = {}
keyword_bids = [set_bit_item]
result = client.KeywordBid.set_auto(keyword_bids)
Keyword:add
name | type | default value |
---|
keywords | list | *required |
keyword = {"Keyworod": "yandex-dircet-api-python", "AdGroupId": "12324324334"}
keywords = [keyword]
result = client.Keyword.add(keywords)
Keyword:delete
name | type | default value |
---|
ids | list | *required |
ids = ['1232432547357348']
result = client.Keyword.delete(ids)
Keyword:get
name | type | default value |
---|
field_names | list | *required |
ids | list | None |
ad_group_ids | list | None |
campaign_ids | list | None |
states | list | None |
statuses | list | None |
serving_statuses | list | None |
modified_since | str | None |
limit | int | 10000 |
offset | int | 0 |
field_names = ['Id', 'Keyword']
result = client.Keyword.delete(field_names, campaign_ids=['23232343583'])
Keyword:resume
name | type | default value |
---|
ids | list | *required |
ids = ['1232432547357348']
result = client.Keyword.resume(ids)
Keyword:suspend
name | type | default value |
---|
ids | list | *required |
ids = ['1232432547357348']
result = client.Keyword.resume(ids)
Keyword:update
name | type | default value |
---|
keywords | list | *required |
keywords = [{'Id': '123123243534', 'Keyword': 'updated yandex'}]
result = client.Keyword.update(keywords)
KeywordsResearch:deduplicate
name | type | default value |
---|
keywords | list | *required |
operation | list | None |
keywords = [{'Id': '123123243534', 'Keyword': 'updated yandex'}]
operation = 'MERGE_DUPLICATES'
result = client.KeywordsResearch.deduplicate(keywords, operation)
KeywordsResearch:has_search_volume
name | type | default value |
---|
field_names | list | *required |
keywords | list | *required |
region_ids | list | *required |
field_names = ['Keyword']
keywords = [{'Id': '123123243534', 'Keyword': 'updated yandex'}]
region_ids = ['123123123']
result = client.KeywordsResearch.has_search_volume(field_names, keywords, region_ids)
Lead:get
name | type | default value |
---|
field_names | list | *required |
turbo_page_ids | list | None |
date_time_from | str | None |
date_time_to | str | None |
limit | int | 10000 |
offset | int | 0 |
field_names = ['TurboPageId', 'TurboPageName', 'id']
result = client.Lead.get(field_names)
NegativeKeywordSharedSet:add
name | type | default value |
---|
negative_keyword_shared_sets | list | *required |
negative_keyword_shared_sets = [{'Name': 'name', 'NegativeKeywords': [123]}]
result = client.Lead.get(negative_keyword_shared_sets)
NegativeKeywordSharedSet:delete
name | type | default value |
---|
ids | list | *required |
ids = [12312325]
result = client.NegativeKeywordSharedSet.delete(ids)
NegativeKeywordSharedSet:get
name | type | default value |
---|
field_names | list | *required |
ids | list | None |
limit | int | 10000 |
offset | int | 0 |
field_names = ['Id', 'Name', 'NegativeKeywords']
result = client.NegativeKeywordSharedSet.get(field_names)
NegativeKeywordSharedSet:update
name | type | default value |
---|
negative_keyword_shared_sets | list | *required |
negative_keyword_shared_sets = [{'Id': '12324234234', 'Name': 'test', 'NegativeKeywords': ['1231321']}]
result = client.NegativeKeywordSharedSet.update(negative_keyword_shared_sets)
RetargetingList:add
name | type | default value |
---|
retargeting_list | list | *required |
retargeting_obj = {}
retargeting_list = [retargeting_obj]
result = client.RetargetingList.add(retargeting_list)
RetargetingList:delete
name | type | default value |
---|
ids | list | *required |
ids = [12313254325345345353]
result = client.RetargetingList.delete(ids)
RetargetingList:get
name | type | default value |
---|
field_names | list | *required |
ids | list | None |
types | list | None |
limit | int | 10000 |
offset | int | 0 |
field_names = ['Type', 'Id', 'Name']
ids = [12313254325345345353]
result = client.RetargetingList.get(field_names, ids=ids)
RetargetingList:update
name | type | default value |
---|
retargeting_list | list | *required |
retargeting_obj = {}
retargeting_list = [retargeting_obj]
result = client.RetargetingList.update(retargeting_list)
Sitelink:add
name | type | default value |
---|
sitelinks_sets | list | *required |
sitelinks = [{'Title': 'sitelink1'}]
sitelinks_sets = [sitelinks]
result = client.Sitelink.add(sitelinks_sets)
Sitelink:delete
name | type | default value |
---|
ids | list | *required |
ids = [12313254325345345353]
result = client.Sitelink.delete(ids)
Sitelink:get
name | type | default value |
---|
field_names | list | *required |
ids | list | None |
sitelinks_field_names | list | None |
limit | int | 10000 |
offset | int | 0 |
field_names = ['Id', 'Sitelinks']
result = client.Sitelink.get(field_names)
TurboPage:get
name | type | default value |
---|
field_names | list | *required |
ids | list | None |
limit | int | 10000 |
offset | int | 0 |
field_names = ['Id', 'Name', 'Href']
result = client.TurboPage.get(field_names)
VCard:add
name | type | default value |
---|
vcards | list | *required |
vcard = {
'CampaignId': '1231231232131',
'Country': '<country>',
'City': '<City>',
'CompanyName': '<CompanyName>',
}
vcards = [vcard]
result = client.VCard.add(vcards)
VCard:delete
name | type | default value |
---|
ids | list | *required |
ids = [12313254325345345353]
result = client.Sitelink.delete(ids)
VCard:get
name | type | default value |
---|
field_names | list | *required |
ids | list | None |
limit | int | 10000 |
offset | int | 0 |
field_names = ['Id', 'Country', 'City']
result = client.VCard.get(field_names)
Report:get
name | type | default value |
---|
selection_criteria | list | *required |
field_names | list | *required |
report_name | str | *required |
report_type | str | *required |
date_range_type | str | *required |
processing_mode | str | auto |
headers | dict | None |
goals | list | None |
attribution_models | list | None |
page | dict | None |
order_by | list | None |
format | str | TSV |
include_vat | str | YES |
include_discount | str | NO |
selection_criteria= {
"DateFrom": date_from.strftime('%Y-%m-%d'),
"DateTo": date_to.strftime('%Y-%m-%d'),
}
field_names = [
"Date",
"Impressions",
"Clicks",
"Cost",
"CriterionId",
"Criterion",
"CampaignId",
"AdId",
"Device",
"AdGroupId",
"CampaignType",
"AvgClickPosition",
"Slot",
"LocationOfPresenceId",
"Placement",
"AvgImpressionPosition",
"LocationOfPresenceName",
"CampaignName",
"AdNetworkType",
]
page = {"Limit": 100000000},
report_name = f"ActualData - 123"
report_type = "CUSTOM_REPORT",
date_range_type = "CUSTOM_DATE"
result = client.Report.get(
selection_criteria=selection_criteria,
field_names=field_names,
report_name=report_name,
report_type=report_type,
date_range_type=date_range_type,
page=page,
)
Client:add
name | type | default value |
---|
login | str | *required |
first_name | str | *required |
last_name | str | *required |
currency | str | *required |
grants | list | None |
notification | dict | None |
settings | dict | None |
result = client.Client.add(login='clid', first_name='ivan', last_name='petrov', currency='RUB')
Client:get
name | type | default value |
---|
field_names | list | *required |
logins | list | None |
archived | str | None |
limit | int | 500 |
offset | int | 0 |
field_names = ['ClientId', 'ClientInfo']
result = client.Client.get(field_names)
TODO: