Unable to list campaigns
muw78 opened this issue · 1 comments
muw78 commented
I am trying to make the most basic request of listing all campaigns of the account (The same credentials with Postman generated Python code correctly return the advertising campaigns of the account):
import logging
from ad_api.api import sponsored_products
my_credentials = dict(
refresh_token="Atzr|Iw______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________Og",
client_id="amzn1.application-oa2-client.2______________________________0",
client_secret="amzn1.oa2-cs.v1.cd____________________________________________________________6d",
profile_id="2______________6",
)
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s:%(levelname)s:%(message)s")
sponsored_products.Campaigns(credentials=my_credentials).list_campaigns()
and I get the following response:
2023-09-21 20:09:13,667:WARNING:Call to deprecated function list_campaigns endpoint: /v2/sp/campaigns method: GET
---------------------------------------------------------------------------
AdvertisingApiTemporarilyUnavailableExceptionTraceback (most recent call last)
/Users/muw/Desktop/code/git/amazon_ads_api/test_adsapi.ipynb Cell 1 line 1
4 my_credentials = dict(
5 refresh_token="Atzr|Iw______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________Og",
6 client_id="amzn1.application-oa2-client.2______________________________0",
7 client_secret="amzn1.oa2-cs.v1.cd____________________________________________________________6d",
8 profile_id="2______________6",
9 )
11 logging.basicConfig(level=logging.DEBUG, format="%(asctime)s:%(levelname)s:%(message)s")
---> 13 sponsored_products.Campaigns(credentials=my_credentials).list_campaigns()
File /opt/homebrew/lib/python3.11/site-packages/ad_api/base/helpers.py:21, in sp_endpoint.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
19 def wrapper(*args, **kwargs):
20 kwargs.update({"path": path, "method": method})
---> 21 return function(*args, **kwargs)
File /opt/homebrew/lib/python3.11/site-packages/ad_api/base/utils.py:20, in Utils.deprecated.<locals>.new_func(*args, **kwargs)
17 @functools.wraps(func)
18 def new_func(*args, **kwargs):
19 logging.warning("Call to deprecated function {} endpoint: {} method: {}".format(func.__name__, kwargs.get('path'), kwargs.get('method')))
---> 20 return func(*args, **kwargs)
File /opt/homebrew/lib/python3.11/site-packages/ad_api/api/sp/campaigns.py:341, in Campaigns.list_campaigns(self, **kwargs)
316 @sp_endpoint('/v2/sp/campaigns', method='GET')
...
314 js = res.content
--> 317 raise exception(status_code, js, headers)
318 exit(res.status_code)
Running the code in the terminal leads to the following response:
➜ amazon_ads_api python3 test.py
2023-09-21 22:19:17,737:WARNING:Call to deprecated function list_campaigns endpoint: /v2/sp/campaigns method: GET
Traceback (most recent call last):
File "/Users/muw/Desktop/code/git/amazon_ads_api/test.py", line 10, in <module>
sponsored_products.Campaigns(credentials=my_credentials).list_campaigns()
File "/opt/homebrew/lib/python3.11/site-packages/ad_api/base/helpers.py", line 21, in wrapper
return function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/ad_api/base/utils.py", line 20, in new_func
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/ad_api/api/sp/campaigns.py", line 341, in list_campaigns
return self._request(kwargs.pop('path'), params=kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/ad_api/base/client.py", line 284, in _request
return self._check_response(res)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/ad_api/base/client.py", line 323, in _check_response
raise exception(status_code, js, headers)
ad_api.base.exceptions.AdvertisingApiTemporarilyUnavailableException: (503, b'<html><body><b>Http/1.1 Service Unavailable</b></body> </html>', {'Server': 'Server', 'Date': 'Thu, 21 Sep 2023 20:19:18 GMT', 'Content-Length': '62', 'Connection': 'keep-alive', 'x-amz-rid': 'A7DYTJW6B5NPYC11W5P6', 'Cache-Control': 'no-cache,no-store', 'Pragma': 'no-cache', 'Vary': 'Content-Type,Accept-Encoding,User-Agent', 'Strict-Transport-Security': 'max-age=47474747; includeSubDomains; preload'})
The following recent question on stackoverflow seems to be referring to the same issue: https://stackoverflow.com/questions/77038320/amazon-ads-api-with-python-amazon-ad-api-packeg
Desktop
- OS: macOS 13.2.1
- Python 3.11.5
- python-amazon-ad-api 0.5.0
- Jupyter Lab in Visual Studio Code Version: 1.82.2
- iTerm2 Build 3.4.20
Please advise.
shavi34 commented
@muw78 Sponsors Product V2 endpoints are deprecated. Please use V3 endpoints to get all campaigns
https://advertising.amazon.com/API/docs/en-us/reference/migration-guides/sp-v2-v3