python-amazon-ad-api

repository·main·Indexed 41 days ago

https://github.com/denisneuf/python-amazon-ad-api

A Python 3 wrapper for Amazon's Advertising API. It provides modules for Sponsored Products (v3), Sponsored Brands (v3/v4), Sponsored Display, Amazon Attribution, Brand Metrics, and the Demand Side Platform (DSP) API. The library includes built-in support for credential management via YAML, marketplace configuration for NA, EU, and FE, and automated pagination handling via the load_all_categories decorator.

Tokens
52.4K
Snippets
177
Records
224
Agent score
51%

What's inside python-amazon-ad-api

  1. Overview of Sponsored Products API 2.0 capabilities

    main

    The Sponsored Products API 2.0 allows for management operations across several advertising entities. You can use this API to manage:

    • Campaigns
    • Ad Groups
    • Keywords and Negative Keywords
    • Product Ads
    • Product Targeting and Negative Product Targeting
    • Bid Recommendations
    • Suggested Keywords
    • Reports and Snapshots
  2. Overview of available API Modules

    main

    The library provides extensive coverage for various Amazon Advertising services. Key modules include:

    • Core/Management: Profiles, Manager Accounts
    • Sponsored Products (v3): Campaigns, Ad Groups, Keywords, Negative Keywords, Product Targeting, Budget Rules, etc.
    • Sponsored Brands (v3/v4): Campaigns, Ad Groups, Keywords, Stores, Brands
    • Sponsored Display: Campaigns, Ad Groups, Targets, Creatives, Forecasts
    • Specialized Services: Amazon Attribution (open beta), Brand Metrics (open beta), DSP (Reports), Portfolios (Note: Portfolios V2 is being deprecated in favor of V3).
  3. Explore the Amazon Advertising API modules

    main

    The library provides specialized modules for different Amazon Advertising services. You can interact with the following APIs:

    • Attribution API: For measuring the impact of advertising.
    • Brand Metrics API: For accessing brand-level performance data.
    • Sponsored Products (sp): For managing sponsored product campaigns.
    • Sponsored Brands (sb): For managing sponsored brand campaigns (v4 supported).
    • Sponsored Display (sd): For managing sponsored display campaigns, including Brand Safety, Budget Rules, Campaigns Budget Usage, Forecast, and Recommendations.
    • DSP (Demand Side Platform): For programmatic advertising management.
    • Advertising Test Account: For testing API calls without affecting live campaigns.
  4. Manage Sponsored Product v3 Campaign Negative Keywords

    main

    The CampaignNegativeKeywordsV3 class provides methods to manage negative keywords for Sponsored Product campaigns using API version 3.0.

    Important Constraints:

    • Sandbox Limitation: Sponsored Product v3 is not available for the Sandbox endpoint.
    • Version: This API uses version 3.0.

    Available operations include creating, listing, updating, and deleting campaign negative keywords.

  5. Use the Localization API to localize advertising data

    main

    The ad_api.api.Localization class provides operations to localize data used when creating advertising campaigns. Localization includes translating text, converting monetary amounts, or mapping entities (like products or keywords) from a source marketplace to target marketplaces.

    Key capabilities include:

    • Currency Localization: Convert monetary amounts between marketplaces.
    • Product Localization: Translate product information (ASIN/SKU) across marketplaces.
    • Keyword Localization: Translate keywords for search targeting.
    • Targeting Expression Localization: Localize targeting expressions (e.g., ASIN or Category matches) for different marketplaces.
  6. Manage portfolios with PortfoliosV3

    main

    The PortfoliosV3 API allows you to manage portfolios that group campaigns together. Notably, the Portfolios API can be used as a sandbox environment for testing purposes.

    Key capabilities include:

    • Listing existing portfolios
    • Creating new portfolios
    • Editing existing portfolios
    • Retrieving budget usage data for portfolios
  7. Manage Sponsored Product v3 Campaign Optimization Rules

    main

    The ad_api.api.sp.CampaignOptimization class provides access to Sponsored Product (SP) v3 campaign optimization rules.

    Important Constraints:

    • Sandbox Limitation: Sponsored Product v3 is not available for the Sandbox endpoint.
    • Access Requirements: This API requires separate access from Amazon Advertising Support. If you lack access, you will receive a 403 error: {'code': 403, 'message': 'Client does not have access to this API', ...}.
    • API Version: This is version 3.0.
  8. Version compatibility for Sponsored Product targeting

    main

    The Product Targeting API contains both version 2.0 and version 3.0 endpoints to maintain backward compatibility.

    Important Migration Notes:

    • Sandbox Limitation: Sponsored Product v3.0 is not available for the Sandbox endpoint. If you are testing in Sandbox, you must use v2.0 endpoints.
    • Migration Path: Users are encouraged to migrate to v3.0 endpoints where possible for better functionality.
    • Endpoint Mapping: The library maps v2.0 endpoints (e.g., /v2/sp/targets) and v3.0 endpoints (e.g., /sp/targets/categories/recommendations) to specific methods within the ad_api.api.sp.Targets class.
  9. Retrieve all audiences using Utils.load_all_categories

    main

    To handle pagination and avoid rate limits when retrieving large sets of audiences, use the @Utils.load_all_categories decorator. This decorator automates the process of following nextToken tokens to fetch all pages.

    Decorator Options:

    • throttle_by_seconds: The number of seconds to wait between requests to prevent throttling.
    • next_token_param: The name of the parameter used for pagination (typically "nextToken").

    When using this decorator, the decorated function becomes a generator that yields response pages.

    import logging
    from ad_api.api import Audiences
    from ad_api.base import AdvertisingApiException, Utils
    
    @Utils.load_all_categories(throttle_by_seconds=5, next_token_param="nextToken")
    def get_all_categories(**kwargs):
        return Audiences(debug=True).list_audiences(**kwargs)
    
    if __name__ == '__main__':
        request = {
            "adType": "SD",
        }
    
        for page in get_all_categories(maxResults=20, body=request):
            result = page.payload
            audiences = result.get("audiences")
            for audience in audiences:
                logging.info(audience)
  10. Manage Brand Safety for Sponsored Display

    main

    The BrandSafety class in ad_api.api.sd allows you to manage the Brand Safety Deny List for Sponsored Display campaigns. This list contains websites and apps that the advertiser wants to exclude from their advertising.

    Important Limitation: Sponsored Display features are not available for the Sandbox endpoint.