@@ -48,7 +48,19 @@ my_credentials = dict(
4848 profile_id= ' your-profile_id' ,
4949)
5050
51- result= sponsored_products .Campaigns (credentials= my_credentials).list_campaigns ()
51+ info = \
52+ {
53+ " stateFilter" :
54+ {
55+ " include" : [
56+ " ENABLED"
57+ ]
58+ }
59+ }
60+
61+ result = sponsored_products .CampaignsV3 (credentials= my_credentials).list_campaigns (
62+ body= info
63+ )
5264
5365```
5466
@@ -80,9 +92,9 @@ Python code
8092from ad_api.api import sponsored_products
8193
8294# Leave empty will use the 'default' account
83- result= sponsored_products.Campaigns ().list_campaigns()
95+ result= sponsored_products.CampaignsV3 ().list_campaigns()
8496# will use germany account data
85- result= sponsored_products.Campaigns (account = " germany" ).list_campaigns()
97+ result= sponsored_products.CampaignsV3 (account = " germany" ).list_campaigns()
8698```
8799
88100
@@ -106,7 +118,7 @@ from ad_api.api import sponsored_products
106118from ad_api.base import Marketplaces
107119
108120# You can pass NA or US, CA, MX or BR for North America and JP, AU or SG for Far East
109- result= sponsored_products.Campaigns (marketplace = Marketplaces.NA ).list_campaigns()
121+ result= sponsored_products.CampaignsV3 (marketplace = Marketplaces.NA ).list_campaigns()
110122
111123```
112124
@@ -118,10 +130,20 @@ You can use a [try](https://docs.python.org/3.10/reference/compound_stmts.html#t
118130from ad_api.api import sponsored_products
119131from ad_api.base import AdvertisingApiException
120132
133+ info = \
134+ {
135+ " stateFilter" :
136+ {
137+ " include" : [
138+ " ENABLED"
139+ ]
140+ }
141+ }
142+
121143try :
122144
123- result = sponsored_products.Campaigns ().get_campaign_extended (
124- campaignId = campaign_id
145+ result = sponsored_products.CampaignsV3 ().list_campaigns (
146+ body = info
125147 )
126148
127149 logging.info(result)
@@ -138,10 +160,21 @@ Use debug=True if you want see some logs like the header you submit to the api e
138160from ad_api.api import sponsored_products
139161from ad_api.base import AdvertisingApiException
140162
163+
164+ info = \
165+ {
166+ " stateFilter" :
167+ {
168+ " include" : [
169+ " ENABLED"
170+ ]
171+ }
172+ }
173+
141174try :
142175
143- result = sponsored_products.Campaigns (debug = True ).get_campaign_extended (
144- campaignId = campaign_id
176+ result = sponsored_products.CampaignsV3 (debug = True ).list_campaigns (
177+ body = info
145178 )
146179
147180 logging.info(result)
@@ -313,38 +346,52 @@ There is a new version 3 of Sponsored Product API, please check the [migration g
313346``` python
314347import logging
315348from ad_api.base import AdvertisingApiException
316- from ad_api.api.sp import Campaigns
349+ from ad_api.api import sponsored_products
317350
318351logging.basicConfig(
319352 level = logging.DEBUG ,
320353 format = " %(asctime)s :%(levelname)s :%(message)s "
321354)
322355
356+ def sp_list_campaigns_v3 (info : dict = None ):
323357
324- credentials = dict (
325- refresh_token = ' your-refresh_token' ,
326- client_id = ' your-client_id' ,
327- client_secret = ' your-client_secret' ,
328- profile_id = ' your-profile_id' ,
329- )
358+ credentials = dict (
359+ refresh_token = ' your-refresh_token' ,
360+ client_id = ' your-client_id' ,
361+ client_secret = ' your-client_secret' ,
362+ profile_id = ' your-profile_id' ,
363+ )
330364
331- try :
365+ try :
366+ result = sponsored_products.CampaignsV3(credentials = credentials, debug = True ).list_campaigns(
367+ body = info
368+ )
369+ payload = result.payload
370+ return payload
371+ except AdvertisingApiException as error:
372+ logging.error(error)
373+ logging.error(error.code)
332374
333- states = ' enabled'
334375
335- res = Campaigns(credentials = credentials, debug = True ).list_campaigns_extended(
336- stateFilter = states
337- )
376+ state_filter = \
377+ {
378+ " stateFilter" :
379+ {
380+ " include" : [
381+ " ENABLED"
382+ ]
383+ }
384+ }
338385
339- campaigns = res.payload
340- for campaign in campaigns:
341- logging.info(campaign)
386+ enabled_campaigns = sp_list_campaigns_v3(state_filter).get(" campaigns" )
342387
343- logging.info(len (campaigns))
388+
389+ for campaign in enabled_campaigns:
390+ logging.info(campaign)
391+
392+ logging.info(len (campaigns))
344393
345394
346- except AdvertisingApiException as error:
347- logging.info(error)
348395
349396```
350397
0 commit comments