python-amazon-ad-api icon indicating copy to clipboard operation
python-amazon-ad-api copied to clipboard

Using deprecated API?

Open dcmcshan opened this issue 11 months ago • 1 comments

Hi there. Wondering if you plan to update to v3? Looks like a useful library.

import logging
from ad_api.api import sponsored_products
from ad_api.base import AdvertisingApiException

try:

# Leave empty will use the 'default' account
    result=sponsored_products.Campaigns(debug=True).list_campaigns()

    logging.info(result)

except AdvertisingApiException as error:
    logging.info(error)

% python extract_sponsored_products.py 2025-01-19 15:25:50,179:WARNING:Call to deprecated function list_campaigns endpoint: /v2/sp/campaigns method: GET 2025-01-19 15:25:51,725:INFO:{'User-Agent': 'python-ad-api-0.6.3', 'Amazon-Advertising-API-ClientId': 'amzn1.application-oa2-client.43760ba9476b4a37a3b673d8039ed2ad', 'Authorization': 'Bearer Atza|IwEBIFNUdJWNsyfvmnlRseIsAIVjwoBA_30mdteb7X2y3JLACULxT5SJaXmKMHSUOciCxRXro6mU6Hzi-dxsFRiakZEgm8Iu6xzhMWg2YI6hI4mdKK3asKTcYPLNdK4JV7POvoD9tYQteSz4wIWEdZ5kgXBmwOlWKtA8p1DxOMrgGnTZ-xf1ahInpKHdlxS-DYBPAfoxYaF2LgFEyDwuaQnKLioqfHvmSCVvqynwJL4NfzXEkDyZAuL707kc-1bP7Pmsl_IkLL9G2ai6LczgC6avtp1E2BFCcpOhTuKkAbaSGvfEhZI2RTd7PVWV2lSZs1tp9JfXrU-Kl8klz3MXr7N4IzS1C0kCK8OBHbpoVvBXI0u8ohNYPB44CuaOqduG-SIFIkPbf_0VlnM1AYvko_QsFrZo18CRZHSDw9z6_vKt_5SH8-SHvqxh-3TDJePoXZII6qIvzf-HU2Mu7cnK5-tj8-K_', 'Content-Type': 'application/json', 'Amazon-Advertising-API-Scope': '3425973802606848'} 2025-01-19 15:25:51,725:INFO:GET https://advertising-api-eu.amazon.com/v2/sp/campaigns 2025-01-19 15:25:51,725:INFO:{'_content': b'{"code":"NOT_FOUND","details":"Method Not Found","requestId":"XFHRFH0DV2349E3XRVWX"}', '_content_consumed': True, '_next': None, 'status_code': 404, 'headers': {'Server': 'Server', 'Date': 'Sun, 19 Jan 2025 22:25:51 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'x-amz-rid': 'XFHRFH0DV2349E3XRVWX', 'x-amz-request-id': 'XFHRFH0DV2349E3XRVWX', 'Vary': 'Content-Type,Accept-Encoding,User-Agent', 'Strict-Transport-Security': 'max-age=47474747; includeSubDomains; preload'}, 'raw': <urllib3.response.HTTPResponse object at 0x1041025c0>, 'url': 'https://advertising-api-eu.amazon.com/v2/sp/campaigns', 'encoding': 'utf-8', 'history': [], 'reason': 'Not Found', 'cookies': <RequestsCookieJar[]>, 'elapsed': datetime.timedelta(microseconds=870697), 'request': <PreparedRequest [GET]>, 'connection': <requests.adapters.HTTPAdapter object at 0x10411d090>} 2025-01-19 15:25:51,726:INFO:(404, {'code': 'NOT_FOUND', 'details': 'Method Not Found', 'requestId': 'XFHRFH0DV2349E3XRVWX'}, {'Server': 'Server', 'Date': 'Sun, 19 Jan 2025 22:25:51 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'x-amz-rid': 'XFHRFH0DV2349E3XRVWX', 'x-amz-request-id': 'XFHRFH0DV2349E3XRVWX', 'Vary': 'Content-Type,Accept-Encoding,User-Agent', 'Strict-Transport-Security': 'max-age=47474747; includeSubDomains; preload'})

dcmcshan avatar Jan 19 '25 22:01 dcmcshan

The version 3 is available:

Try this:

import logging
from ad_api.api import sponsored_products
from ad_api.base import AdvertisingApiException

try:

# Leave empty will use the 'default' account
    result=sponsored_products.CampaignsV3(debug=True).list_campaigns()

    logging.info(result)

except AdvertisingApiException as error:
    logging.info(error)

Let me know if it works for you

denisneuf avatar Jan 20 '25 02:01 denisneuf

Hello!

I am currently learning to use the python-amazon-ad-api library and have reached the Manager Account section. When trying to use the associate_manager_accounts() method, I noticed that I need to explicitly write the account_id of the region to be bound in the code, as shown below:

amz_manager_account_id = 'amzn1.ads1.ma1.ewpohpn123456789987654321'
account_id = 'ENTITY1123456789012'
roles = ['ENTITY_VIEWER']
type_account = 'ACCOUNT_ID'

Currently, I can only obtain the account_id from the URL of my advertising account web page (such as the ENTITY1123456789012 part in the URL).

I would like to know if there is a class or method in the API that can directly obtain the account_id based on the profile_id? Or is there another recommended way to obtain this ID without having to manually extract it from the webpage URL?

Thank you for your help!

Best regards,

---------------------
https://python-amazon-ad-api.readthedocs.io/en/latest/api/manager_accounts.html#ad_api.api.ManagerAccounts.ManagerAccounts.associate_manager_accounts

cn-knight avatar Mar 17 '25 10:03 cn-knight

MOved previous one to discussions

denisneuf avatar Mar 31 '25 03:03 denisneuf