Localization

https://dtrnk0o2zy01c.cloudfront.net/openapi/en-us/dest/Localization_prod_3p.json.

This API provides operations to localize data used when creating advertising campaigns. Depending on the type of data, localization may entail translating text, converting monetary amounts, or mapping an entity in a source marketplace to an analogous entity in one or more target marketplaces.

class ad_api.api.Localization(account='default', marketplace: Marketplaces = Marketplaces.EU, credentials=None, proxies=None, verify=True, timeout=None, debug=False, access_token=None)
get_currency_extended(body: dict, str, version: int = 1) ApiResponse

Gets an array of localized currencies extended with currency code and the country_code for better understanding in their target marketplaces, with the advertiser ID and source marketplace ID passed in through the header and body

version’: int [optional] Will use content body “application/vnd.currencylocalization.v”+str(version)+”+json”

body: | REQUIRED | { | ‘localizeCurrencyRequests’: list | [ | ‘LocalizationCurrencyRequest’: dict | { | ‘currency’: LocalizationCurrency: dict | { | “amount”: int | } | } | ] | } | ‘targetCountryCodes’: list, A list of two-letter country codes. When both marketplaceId and countryCode are present, countryCode is ignored. Please refer to the table above for a list of supported country codes. | ‘sourceCountryCode’: string | ‘sourceMarketplaceId’: string | ‘targetMarketplaces’: list }

Warning

This method get_currency_extended is a helper that will extend the response and return country codes abd currency to contextualize better the results

Note

If you do not provide any filter or the filters are wide it will return tons the audiences

### Example creating a dictionary and using MarketplacesIds Enum to simplify the task

import logging
from ad_api.api import Localization
from ad_api.base import AdvertisingApiException, MarketplacesIds

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s:%(levelname)s:%(message)s"
)

def get_currency_extended(data: (str, dict), version: int = 1):
    try:

        result = Localization(debug=True).get_currency_extended(
            version=version,
            body=data
        )

        logging.info(result)

    except AdvertisingApiException as error:
        logging.info(error)


if __name__ == '__main__':

    source_country_code = "DE"
    source_marketplace_id = MarketplacesIds[source_country_code].value
    target_country_codes = ["GB", "US", "JP"]
    amount_1 = 10
    amount_2 = 15

    request = \
    {
        'localizeCurrencyRequests': [
            {
                'currency': {
                    'amount': amount_1
                }
            },
            {
                'currency': {
                    'amount': amount_2
                }
            }

        ],
        'targetCountryCodes': target_country_codes,
        'sourceCountryCode': source_country_code,
        'sourceMarketplaceId': source_marketplace_id,
        'targetMarketplaces': [MarketplacesIds[target_country_code].value for target_country_code in target_country_codes]
    }

    get_currency_extended(request, version=1) # You could submit version=2

# Static .json file in case want to use as example

{
    "localizeCurrencyRequests": [
        {"currency": {"amount": 10}},
        {"currency": {"amount": 15}}
    ],
    "targetCountryCodes": ["GB", "US", "JP"],
    "sourceCountryCode": "DE",
    "sourceMarketplaceId": "A1PA6795UKMFR9",
    "targetMarketplaces": ["A1F83G8C2ARO7P", "ATVPDKIKX0DER", "A1VC38T7YXB528"]
}

Download json the file to use:

### Example using the above file as request (MarketplacesIds not needed)

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

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s:%(levelname)s:%(message)s"
)

def get_currency_extended(data: (str, dict), version: int = 1):
try:

    result = Localization(debug=True).get_currency_extended(
        version=version,
        body=data
    )

    logging.info(result)

except AdvertisingApiException as error:
    logging.info(error)

if __name__ == '__main__':

    file_name = "../test/localizations/request_currency.json"
    get_currency_extended(file_name) # No version include will get version 1
    # get_currency_extended(file_name, version=2)

# Result using version=1 application/vnd.currencylocalization.v1+json

{
    "localizedCurrencyResponses": [
        {
            "localizedCurrencies": {
                "A1F83G8C2ARO7P": {
                    "amount": 8.29,
                    "currency": "GBP",
                    "country_code": "UK"
                },
                "ATVPDKIKX0DER": {
                    "amount": 10.83,
                    "currency": "USD",
                    "country_code": "US"
                },
                "A1VC38T7YXB528": {
                    "amount": 1363.0,
                    "currency": "JPY",
                    "country_code": "JP"
                },
            },
            "status": "SUCCESS",
            "sourceCurrency": {
                "amount": 10,
                "country_code": "DE",
                "currency": "EUR",
                "source_marketplace_id": "A1PA6795UKMFR9"
            },
        },
        {
            "localizedCurrencies": {
                "A1F83G8C2ARO7P": {
                    "amount": 12.43,
                    "currency": "GBP",
                    "country_code": "UK"
                },
                "ATVPDKIKX0DER": {
                    "amount": 16.25,
                    "currency": "USD",
                    "country_code": "US"
                },
                "A1VC38T7YXB528": {
                    "amount": 2045.0,
                    "currency": "JPY",
                    "country_code": "JP"
                },
            },
            "status": "SUCCESS",
            "sourceCurrency": {
                "amount": 15,
                "country_code": "DE",
                "currency": "EUR",
                "source_marketplace_id": "A1PA6795UKMFR9"
            }
        }
    ]
}

# Result using version=2 application/vnd.currencylocalization.v2+json

{
    "localizedCurrencyResponses": [
        {
            "sourceCurrency": {
                "amount": 10.0,
                "country_code": "DE",
                "currency": "EUR",
                "source_marketplace_id": "A1PA6795UKMFR9"
            },
            "localizedCurrencies": {
                "A1F83G8C2ARO7P": {
                    "amount": 8.29,
                    "currency": "GBP",
                    "country_code": "UK"
                },
                "ATVPDKIKX0DER": {
                    "amount": 10.83,
                    "currency": "USD",
                    "country_code": "US"
                },
                "A1VC38T7YXB528": {
                    "amount": 1363.0,
                    "currency": "JPY",
                    "country_code": "JP"
                },
            },
            "localizedCurrency": {
                "A1F83G8C2ARO7P": {
                    "amount": 8.29,
                    "currency": "GBP",
                    "country_code": "UK"
                },
                "ATVPDKIKX0DER": {
                    "amount": 10.83,
                    "currency": "USD",
                    "country_code": "US"
                },
                "A1VC38T7YXB528": {
                    "amount": 1363.0,
                    "currency": "JPY",
                    "country_code": "JP"
                },
            },
            "localizedCurrencyResults": {
                "A1F83G8C2ARO7P": {
                    "localizedCurrency": {
                        "amount": 8.29,
                        "currency": "GBP",
                        "country_code": "UK"
                    },
                    "status": "SUCCESS"
                },
                "ATVPDKIKX0DER": {
                    "localizedCurrency": {
                        "amount": 10.83,
                        "currency": "USD",
                        "country_code": "US"
                    },
                    "status": "SUCCESS"
                },
                "A1VC38T7YXB528": {
                    "localizedCurrency": {
                        "amount": 1363.0,
                        "currency": "JPY",
                        "country_code": "JP"
                    },
                    "status": "SUCCESS"
                },
            },
            "status": "SUCCESS"
        },
        {
            "sourceCurrency": {
                "amount": 15.0,
                "country_code": "DE",
                "currency": "EUR",
                "source_marketplace_id": "A1PA6795UKMFR9"
            },
            "localizedCurrencies": {
                "A1F83G8C2ARO7P": {
                    "amount": 12.43,
                    "currency": "GBP",
                    "country_code": "UK"
                },
                "ATVPDKIKX0DER": {
                    "amount": 16.25,
                    "currency": "USD",
                    "country_code": "US"
                },
                "A1VC38T7YXB528": {
                    "amount": 2045.0,
                    "currency": "JPY",
                    "country_code": "JP"
                },
            },
            "localizedCurrency": {
                "A1F83G8C2ARO7P": {
                    "amount": 12.43,
                    "currency": "GBP",
                    "country_code": "UK"
                },
                "ATVPDKIKX0DER": {
                    "amount": 16.25,
                    "currency": "USD",
                    "country_code": "US"
                },
                "A1VC38T7YXB528": {
                    "amount": 2045.0,
                    "currency": "JPY",
                    "country_code": "JP"
                },
            },
            "localizedCurrencyResults": {
                "A1F83G8C2ARO7P": {
                    "localizedCurrency": {
                        "amount": 12.43,
                        "currency": "GBP",
                        "country_code": "UK"
                    },
                    "status": "SUCCESS"
                },
                "ATVPDKIKX0DER": {
                    "localizedCurrency": {
                        "amount": 16.25,
                        "currency": "USD",
                        "country_code": "US"
                    },
                    "status": "SUCCESS"
                },
                "A1VC38T7YXB528": {
                    "localizedCurrency": {
                        "amount": 2045.0,
                        "currency": "JPY",
                        "country_code": "JP"
                    },
                    "status": "SUCCESS"
                }
            },
            "status": "SUCCESS"
        }
    ]
}
get_currency(body: dict, str, version: int = 1, **kwargs) ApiResponse

Gets an array of localized currencies in their target marketplaces, with the advertiser ID and source marketplace ID passed in through the header and body

Returns localized currencies within specified marketplaces.

Requires one of these permissions: ["advertiser_campaign_edit","advertiser_campaign_view"]

version’: int [optional] Will use content body “application/vnd.currencylocalization.v”+str(version)+”+json”

body: | REQUIRED | { | ‘localizeCurrencyRequests’: list | [ | ‘LocalizationCurrencyRequest’: dict | { | ‘currency’: LocalizationCurrency: dict | { | “amount”: int | } | } | ] | } | ‘targetCountryCodes’: list, A list of two-letter country codes. When both marketplaceId and countryCode are present, countryCode is ignored. Please refer to the table above for a list of supported country codes. | ‘sourceCountryCode’: string | ‘sourceMarketplaceId’: string | ‘targetMarketplaces’: list }

# Same json file to use

{
    "localizeCurrencyRequests": [
        {"currency": {"amount": 10}},
        {"currency": {"amount": 15}}
    ],
    "targetCountryCodes": ["GB", "US", "JP"],
    "sourceCountryCode": "DE",
    "sourceMarketplaceId": "A1PA6795UKMFR9",
    "targetMarketplaces": ["A1F83G8C2ARO7P", "ATVPDKIKX0DER", "A1VC38T7YXB528"]
}

Download json the file to use:

### Example using the above file as request (MarketplacesIds not needed)

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

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s:%(levelname)s:%(message)s"
)

def get_currency(data: (str, dict), version: int = 1):

    try:

        result = Localization(debug=True).get_currency(
            version=version,
            body=data
        )

        logging.info(result)

    except AdvertisingApiException as error:
        logging.info(error)

if __name__ == '__main__':

    file_name = "../test/localizations/request_currency.json"
    try:

        with open(file_name, mode="r", encoding="utf-8") as file:
            get_currency(file_name, version=1)
            file.close()

    except FileNotFoundError as e:
        logging.info(e)

# Result using version=1 application/vnd.currencylocalization.v1+json

{
    "localizedCurrencyResponses": [
        {
            "localizedCurrencies": {
                "A1F83G8C2ARO7P": {"amount": 8.29},
                "ATVPDKIKX0DER": {"amount": 10.83},
                "A1VC38T7YXB528": {"amount": 1363.0}
            },
            "status": "SUCCESS"
        },
        {
            "localizedCurrencies": {
                "A1F83G8C2ARO7P": {"amount": 12.43},
                "ATVPDKIKX0DER": {"amount": 16.25},
                "A1VC38T7YXB528": {"amount": 2045.0}
            },
            "status": "SUCCESS"
        },
    ]
}

# Result using version=2 application/vnd.currencylocalization.v2+json

{
    "localizedCurrencyResponses": [
        {
            "sourceCurrency": {"amount": 10.0},
            "localizedCurrencies": {
                "A1F83G8C2ARO7P": {"amount": 8.29},
                "ATVPDKIKX0DER": {"amount": 10.83},
                "A1VC38T7YXB528": {"amount": 1363.0}
            },
            "localizedCurrency": {
                "A1F83G8C2ARO7P": {"amount": 8.29},
                "ATVPDKIKX0DER": {"amount": 10.83},
                "A1VC38T7YXB528": {"amount": 1363.0}
            },
            "localizedCurrencyResults": {
                "A1F83G8C2ARO7P": {
                    "localizedCurrency": {"amount": 8.29},
                    "status": "SUCCESS"
                },
                "ATVPDKIKX0DER": {
                    "localizedCurrency": {"amount": 10.83},
                    "status": "SUCCESS"
                },
                "A1VC38T7YXB528": {
                    "localizedCurrency": {"amount": 1363.0},
                    "status": "SUCCESS"
                },
            },
            "status": "SUCCESS"
        },
        {
            "sourceCurrency": {"amount": 15.0},
            "localizedCurrencies": {
                "A1F83G8C2ARO7P": {"amount": 12.43},
                "ATVPDKIKX0DER": {"amount": 16.25},
                "A1VC38T7YXB528": {"amount": 2045.0}
            },
            "localizedCurrency": {
                "A1F83G8C2ARO7P": {"amount": 12.43},
                "ATVPDKIKX0DER": {"amount": 16.25},
                "A1VC38T7YXB528": {"amount": 2045.0}
            },
            "localizedCurrencyResults": {
                "A1F83G8C2ARO7P": {
                    "localizedCurrency": {"amount": 12.43},
                    "status": "SUCCESS"
                },
                "ATVPDKIKX0DER": {
                    "localizedCurrency": {"amount": 16.25},
                    "status": "SUCCESS"
                },
                "A1VC38T7YXB528": {
                    "localizedCurrency": {"amount": 2045.0},
                    "status": "SUCCESS"
                }
            },
            "status": "SUCCESS"
        }
    ]
}

get_products(body: dict, str, version: int = 1, **kwargs) ApiResponse

Localizes (maps) products from a source marketplace to one or more target marketplaces. The localization process succeeds for a given target marketplace if a product matching the source product can be found there and the advertiser is eligible to advertise it. Seller requests have an additional condition: the SKU of a localized product must match the SKU of the source product.

Requires one of these permissions: ["advertiser_campaign_edit","advertiser_campaign_view"]

version’: int [optional] Will use content body “application/vnd.productlocalization.v”+str(version)+”+json”

body: | REQUIRED | { | ‘localizeProductRequests’: list | [ | ‘LocalizationProductRequest’: dict | { | ‘product’: LocalizationProduct: dict | { | “asin”: string, The product’s Amazon Standard Identification Number. Required for entityType=VENDOR. If caller’s entityType is SELLER, this field is optional and can yield better localization results if included. | “sku”: string, The product’s Stock Keeping Unit. Required for entityType=SELLER. If caller’s entityType is VENDOR, this field is ignored. | } | } | ] | } | ‘adType’: string, Used to confirm that the caller is eligible to advertise localized products. Currently, only Sponsored Products advertising is supported. [ SPONSORED_PRODUCTS ] | ‘sourceCountryCode’: string A two-letter country code. When both marketplaceId and countryCode are present, countryCode is ignored. Please refer to the table above for a list of supported country codes. | ‘entityType’: string [required] The type of the advertiser accounts for which IDs are specified elsewhere in the request. [ SELLER, VENDOR ] | ‘sourceMarketplaceId’: string The ID of the source marketplace. Please see the table within the description of the target details object for supported values. | ‘targetDetails’: list | ‘LocalizationProductTargetDetails’: dict The target details for the LocalizationProductRequests. There must be only one target details object per marketplace ID. The advertiser ID may be repeated across target details objects. The order of target details objects is irrelevant. The following marketplaces are supported for product localization: | { | “marketplaceId”: string, The ID of a target marketplace (a marketplace in which the caller wishes to localize the specified products). For example, if the caller is an advertiser based in the UK (marketplace ID A1F83G8C2ARO7P) and wishes to localize a product to Germany (marketplace ID A1PA6795UKMFR9), the target marketplace ID is that of Germany, i.e., A1PA6795UKMFR9. The following marketplaces are supported for product localization: | “countryCode”: string, A two-letter country code. When both marketplaceId and countryCode are present, countryCode is ignored. Please refer to the table above for a list of supported country codes. | “advertiserId”: string, [required] The advertiser ID of the caller in the associated target marketplace. The ID of the source advertiser account. This may be either a marketplace-specific obfuscated ID (AD9EUOBWMS33M), an entity ID (ENTITYYXZDK86N86HG), or a global account ID (amzn1.ads-account.g.e0kbzpoe2gkpai1pqeaca59k8). This is the advertiser ID returned by the Profiles API. An entity ID (one starting with “ENTITY”), or a global account advertiser ID may be provided instead. | } }

Note

The Product Localization supports 2 different types of content (Content-Type) so is possible get 2 different responses Just pass an optional parameter (2) as int if you want different option, default is version 1.

### Example with a dictionary using marketplaceId for source and target and version 1

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

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s:%(levelname)s:%(message)s"
)

def get_products(data: (str, dict), version: int = 1):

    try:

        result = Localization(debug=True).get_products(
            version=version,
            body=data
        )

        logging.info(result)

    except AdvertisingApiException as error:
        logging.info(error)


if __name__ == '__main__':

    product_request = \
    {
        "localizeProductRequests": [
            {
                "product": {
                    "asin": "B000000000",
                    "sku": "SKU-OF-B000000000"
                }
            }
        ],
        "adType": "SPONSORED_PRODUCTS",
        "entityType": "SELLER",
        "sourceMarketplaceId": "A1RKKUPIHCS9HS",
        "sourceAdvertiserId": "AD9EUOBWMS33M",
        "targetDetails": [
            {
                "marketplaceId": "A1F83G8C2ARO7P",
                "advertiserId": "AD9EUOBWMS33M"
            }
        ]
    }

    get_products(product_request)

### Example with a dictionary using countryCode for source and target and version 2

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

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s:%(levelname)s:%(message)s"
)

def get_products(data: (str, dict), version: int = 1):

    try:

        result = Localization(debug=True).get_products(
            version=version,
            body=data
        )

        logging.info(result)

    except AdvertisingApiException as error:
        logging.info(error)


if __name__ == '__main__':

    product_request = \
    {
        "localizeProductRequests": [
            {
                "product": {
                    "asin": "B000000000",
                    "sku": "SKU-OF-B000000000"
                }
            }
        ],
        "adType": "SPONSORED_PRODUCTS",
        "entityType": "SELLER",
        "sourceCountryCode": "ES",
        "sourceAdvertiserId": "AD9EUOBWMS33M",
        "targetDetails": [
            {
                "countryCode": "FR",
                "advertiserId": "AD9EUOBWMS33M"
            }
        ]
    }

    get_products(product_request, version=2)

# Result using version=1 application/vnd.productlocalization.v1+json

{
    "localizedProductResponses": [
        {
            "localizedProducts": {
                "A1F83G8C2ARO7P": {
                    "asin": "B000000000",
                    "sku": "SKU-OF-B000000000"
                }
            },
            "status": "SUCCESS"
        }
    ]
}

# Result when the product can’t be localize version=1

{
    "localizedProductResponses": [
        {"errorCode": "INTERNAL_ERROR", "localizedProducts": {}, "status": "FAILURE"}
    ]
}

# Result using version=2 application/vnd.productlocalization.v2+json

{
    "localizedProductResponses": [
        {
            "localizedProductResults": {
                "FR": {
                    "localizedProduct": {
                        "asin": "B000000000",
                        "sku": "SKU-OF-B000000000"
                    },
                    "status": "SUCCESS"
                }
            },
            "localizedProducts": {
                "FR": {
                    "asin": "B000000000",
                    "sku": "SKU-OF-B000000000"
                }
            },
            "sourceProduct": {
                "asin": "B000000000",
                "sku": "SKU-OF-B000000000"
            },
            "status": "SUCCESS"
        }
    ]
}

# Result when the product can’t be localize version=2

{
    "localizedProductResponses": [
        {
            "errorCode": "INTERNAL_ERROR",
            "localizedProductResults": {
                "BR": {
                    "errorCode": "INTERNAL_ERROR",
                    "messages": [
                        "Product(asin=B000000000, sku=SKU-OF-B000000000) failed to localize from A1RKKUPIHCS9HS to BR"
                    ],
                    "status": "FAILURE"
                }
            },
            "localizedProducts": {},
            "sourceProduct": {
                "asin": "B000000000",
                "sku": "SKU-OF-B000000000"
            },
            "status": "FAILURE"
        }
    ]
}

### Example Request as json by Country Code

Download json the file to use:

{
    "localizeProductRequests": [
        {
            "product": {
                "asin": "B000000000",
                "sku": "SKU-OF-B000000000"
            }
        }
    ],
    "adType": "SPONSORED_PRODUCTS",
    "entityType": "SELLER",
    "sourceCountryCode": "ES",
    "sourceAdvertiserId": "AD9EUOBWMS33M",
    "targetDetails": [{"countryCode": "FR", "advertiserId": "AD9EUOBWMS33M"}]
}

### Example Request as json by Marketplace ID

Download json the file to use:

{
    "localizeProductRequests": [
        {
            "product": {
                "asin": "B000000000",
                "sku": "SKU-OF-B000000000"
            }
        }
    ],
    "adType": "SPONSORED_PRODUCTS",
    "entityType": "SELLER",
    "sourceMarketplaceId": "A1RKKUPIHCS9HS",
    "sourceAdvertiserId": "AD9EUOBWMS33M",
    "targetDetails": [
        {"marketplaceId": "A2Q3Y263D00KWC", "advertiserId": "AD9EUOBWMS33M"}
    ]
}
get_keywords(body: dict, str, version: int = 1, **kwargs) ApiResponse

Returns localized keywords within specified marketplaces or locales.

Requires one of these permissions: ["advertiser_campaign_edit","advertiser_campaign_view"]

version’: int [optional] Will use content body “application/vnd.keywordlocalization.v”+str(version)+”+json”

body: | REQUIRED | { | ‘localizeKeywordRequests’: list List of LocalizationKeywordRequests. The order will be maintained in the response maxItems: 1000 | [ | ‘LocalizationKeywordRequest’: dict A LocalizationKeywordRequest object. Contains information needed about the keyword to be localized. | ‘localizationKeyword’: dict An object containing information about a keyword. | { | ‘keyword’: str The keyword string. | } | ] | ‘sourceDetails’: dict | { | ‘marketplaceId’: string | ‘countryCode’: string | ‘locale’: string | } | } | ‘targetDetails’: dict | { | ‘marketplaceIds’: string | ‘countryCodes’: string | ‘locales’: string | } | } | ‘targetCountryCodes’: list, A list of two-letter country codes. When both marketplaceId and countryCode are present, countryCode is ignored. Please refer to the table above for a list of supported country codes. | ‘sourceCountryCode’: string | ‘sourceMarketplaceId’: string | ‘targetMarketplaces’: list }

Note

The Keyword Localization supports 2 different types of content (Content-Type) so is possible get 2 different responses Just pass an optional parameter (2) as int if you want different option, default is version 1.

### Example creating a dynamic dict based on a list of keywords using countryCode for source and Locale to retrieve the locales of targets

import logging
from ad_api.api import Localization
from ad_api.base import AdvertisingApiException, Locales

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s:%(levelname)s:%(message)s"
)

def get_keywords(data: (str, dict), version: int = 1):
    try:

        result = Localization(debug=True).get_keywords(
            version=version,
            body=data
        )

        logging.info(result)

    except AdvertisingApiException as error:
        logging.info(error)
    except KeyboardInterrupt as error:
        logging.info(error)


if __name__ == '__main__':

    keywords = ['máquina', 'diagnosis', 'diagnosis multimarca', 'coche', 'automóvil', 'frenos', 'presión', 'neumáticos']
    source_country_code = "ES"
    target_country_codes = ["GB", "FR", "IT", "DE", "CN", "NL", "SE"]

    keywords_request = \
        {
            "localizeKeywordRequests": [{"localizationKeyword": {"keyword": keyword}} for keyword in keywords],
            "sourceDetails": {
                "countryCode": source_country_code,
            },
            "targetDetails": {
                "locales": [Locales[target_country_code].value for target_country_code in target_country_codes]
            }
        }

    get_keywords(keywords_request)
    # get_keywords(keywords_request, version=2)

### Example static request_keywords_locale.json

{
    "localizeKeywordRequests": [
        {"localizationKeyword": {"keyword": "máquina"}},
        {"localizationKeyword": {"keyword": "diagnosis"}},
        {"localizationKeyword": {"keyword": "diagnosis multimarca"}},
        {"localizationKeyword": {"keyword": "coche"}},
        {"localizationKeyword": {"keyword": "automóvil"}},
        {"localizationKeyword": {"keyword": "frenos"}},
        {"localizationKeyword": {"keyword": "presión"}},
        {"localizationKeyword": {"keyword": "neumáticos"}}
    ],
    "sourceDetails": {"countryCode": "ES"},
    "targetDetails": {
        "locales": ["en_GB", "fr_FR", "it_IT", "de_DE", "nl_NL", "sv_SE"]
    }
}

Download json the file to use

### Example result_keyword_locale.json

{
    "localizedKeywordResponses": [
        {
            "sourceKeyword": {"keyword": "máquina"},
            "localizedKeywords": {
                "it_IT": {"keyword": "macchina"},
                "en_GB": {"keyword": "machine"},
                "sv_SE": {"keyword": "maskin"},
                "fr_FR": {"keyword": "machine"},
                "de_DE": {"keyword": "Maschine"},
                "nl_NL": {"keyword": "machine"}
            },
            "localizedKeywordResults": {
                "it_IT": {
                    "localizedKeyword": {"keyword": "macchina"},
                    "status": "SUCCESS"
                },
                "en_GB": {
                    "localizedKeyword": {"keyword": "machine"},
                    "status": "SUCCESS"
                },
                "sv_SE": {
                    "localizedKeyword": {"keyword": "maskin"},
                    "status": "SUCCESS"
                },
                "fr_FR": {
                    "localizedKeyword": {"keyword": "machine"},
                    "status": "SUCCESS"
                },
                "de_DE": {
                    "localizedKeyword": {"keyword": "Maschine"},
                    "status": "SUCCESS"
                },
                "nl_NL": {
                    "localizedKeyword": {"keyword": "machine"},
                    "status": "SUCCESS"
                },
            },
            "status": "SUCCESS"
        },
        {...}
    ]
}

### Example creating a dynamic dict based on a list of keywords using Locale for source and Country Codes for targets

import logging
from ad_api.api import Localization
from ad_api.base import AdvertisingApiException, Locales

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s:%(levelname)s:%(message)s"
)

def get_keywords(data: (str, dict), version: int = 1):
    try:

        result = Localization(debug=True).get_keywords(
            version=version,
            body=data
        )

        logging.info(result)

    except AdvertisingApiException as error:
        logging.info(error)
    except KeyboardInterrupt as error:
        logging.info(error)


if __name__ == '__main__':

    keywords = ['máquina', 'diagnosis', 'diagnosis multimarca', 'coche', 'automóvil', 'frenos', 'presión', 'neumáticos']
    source_country_code = "ES"
    source_locale = Locales[source_country_code].value
    target_country_codes = ["GB", "FR", "IT", "DE", "CN", "NL", "SE"]

    keywords_request = \
        {
            "localizeKeywordRequests": [{"localizationKeyword": {"keyword": keyword}} for keyword in keywords],
            "sourceDetails": {
                "locale": source_locale
            },
            "targetDetails": {
                "countryCodes": target_country_codes,
            }
        }

    get_keywords(keywords_request)
    # get_keywords(keywords_request, version=2)

### Example static request_keywords_locales.json

{
    "localizeKeywordRequests": [
        {"localizationKeyword": {"keyword": "máquina"}},
        {"localizationKeyword": {"keyword": "diagnosis"}},
        {"localizationKeyword": {"keyword": "diagnosis multimarca"}},
        {"localizationKeyword": {"keyword": "coche"}},
        {"localizationKeyword": {"keyword": "automóvil"}},
        {"localizationKeyword": {"keyword": "frenos"}},
        {"localizationKeyword": {"keyword": "presión"}},
        {"localizationKeyword": {"keyword": "neumáticos"}}
    ],
    "sourceDetails": {"locale": "es_ES"},
    "targetDetails": {"countryCodes": ["GB", "FR", "IT", "DE", "NL", "SE"]}
}

Download json the file to use

### Example result keyword GB >> DE, SE, IT, FR, ES, NL

{
    "localizedKeywordResponses": [
        {
            "sourceKeyword": {"keyword": "anti-block system"},
            "localizedKeywords": {
                "DE": {"keyword": "Antiblockiersystem"},
                "SE": {"keyword": "antiblocksystem"},
                "IT": {"keyword": "sistema anti-blocco"},
                "FR": {"keyword": "système anti-blocage"},
                "ES": {"keyword": "sistema antibloqueo"},
                "NL": {"keyword": "anti-blokkeersysteem"}
            },
            "localizedKeywordResults": {
                "DE": {
                    "localizedKeyword": {"keyword": "Antiblockiersystem"},
                    "status": "SUCCESS"
                },
                "SE": {
                    "localizedKeyword": {"keyword": "antiblocksystem"},
                    "status": "SUCCESS"
                },
                "IT": {
                    "localizedKeyword": {"keyword": "sistema anti-blocco"},
                    "status": "SUCCESS"
                },
                "FR": {
                    "localizedKeyword": {"keyword": "système anti-blocage"},
                    "status": "SUCCESS"
                },
                "ES": {
                    "localizedKeyword": {"keyword": "sistema antibloqueo"},
                    "status": "SUCCESS"
                },
                "NL": {
                    "localizedKeyword": {"keyword": "anti-blokkeersysteem"},
                    "status": "SUCCESS"
                }
            },
            "status": "SUCCESS"
        }
    ]
}

### Example creating a dynamic dict based on a list of keywords using MarketplacesIds for both source and targets

import logging
from ad_api.api import Localization
from ad_api.base import AdvertisingApiException, MarketplacesIds

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s:%(levelname)s:%(message)s"
)

def get_keywords(data: (str, dict), version: int = 1):
    try:

        result = Localization(debug=True).get_keywords(
            version=version,
            body=data
        )

        logging.info(result)

    except AdvertisingApiException as error:
        logging.info(error)
    except KeyboardInterrupt as error:
        logging.info(error)


if __name__ == '__main__':

    keywords = ['máquina', 'diagnosis', 'diagnosis multimarca', 'coche', 'automóvil', 'frenos', 'presión', 'neumáticos']
    source_country_code = "ES"
    source_marketplace_id = MarketplacesIds[source_country_code].value
    target_country_codes = ["GB", "FR", "IT", "DE", "NL", "SE"]

    keywords_request = \
        {
            "localizeKeywordRequests": [{"localizationKeyword": {"keyword": keyword}} for keyword in keywords],
            "sourceDetails": {
                "marketplaceId": source_marketplace_id
            },
            "targetDetails": {
                "marketplaceIds": [MarketplacesIds[target_country_code].value for target_country_code in target_country_codes],
            }
        }

    get_keywords(keywords_request)
    # get_keywords(keywords_request, version=2)

### Example static request_keywords_marketplace_id.json

{
    "localizeKeywordRequests": [
        {"localizationKeyword": {"keyword": "máquina"}},
        {"localizationKeyword": {"keyword": "diagnosis"}},
        {"localizationKeyword": {"keyword": "diagnosis multimarca"}},
        {"localizationKeyword": {"keyword": "coche"}},
        {"localizationKeyword": {"keyword": "automóvil"}},
        {"localizationKeyword": {"keyword": "frenos"}},
        {"localizationKeyword": {"keyword": "presión"}},
        {"localizationKeyword": {"keyword": "neumáticos"}}
    ],
    "sourceDetails": {"marketplaceId": "A1RKKUPIHCS9HS"},
    "targetDetails": {
        "marketplaceIds": [
            "A1F83G8C2ARO7P",
            "A13V1IB3VIYZZH",
            "APJ6JRA9NG5V4",
            "A1PA6795UKMFR9",
            "A1805IZSGTT6HS",
            "A2NODRKZP88ZB9"
        ]
    },
}

Download json the file to use

### Example result keyword FR >> IT, ES, GB

{
    "localizedKeywordResponses": [
        {
            "sourceKeyword": {"keyword": "rondelle d'essuie-glace"},
            "localizedKeywords": {
                "APJ6JRA9NG5V4": {"keyword": "tergicristallo"},
                "A1RKKUPIHCS9HS": {"keyword": "limpiaparabrisas"},
                "A1F83G8C2ARO7P": {"keyword": "windscreen wiper washer"}
            },
            "localizedKeywordResults": {
                "APJ6JRA9NG5V4": {
                    "localizedKeyword": {"keyword": "tergicristallo"},
                    "status": "SUCCESS"
                },
                "A1RKKUPIHCS9HS": {
                    "localizedKeyword": {"keyword": "limpiaparabrisas"},
                    "status": "SUCCESS"
                },
                "A1F83G8C2ARO7P": {
                    "localizedKeyword": {"keyword": "windscreen wiper washer"},
                    "status": "SUCCESS"
                },
            },
            "status": "SUCCESS"
        }
    ]
}

get_targeting_expression(*args, **kwargs)

Localizes targeting expressions used for advertising targeting.

Localizes (maps) targeting expressions from a source marketplace to one or more target marketplaces.

Requires one of these permissions: ["advertiser_campaign_edit","advertiser_campaign_view"]

version’: int [optional] Will use content body “application/vnd.targetingexpressionlocalization.v”+str(version)+”+json”

body: | REQUIRED | { | ‘targetingExpressionLocalizationRequest’: list | [ | ‘targetDetailsList’: dict LocalizationTargetingTargetDetails | { | ‘marketplaceId’: string The ID of the target marketplace. For example, when mapping data from the UK (marketplace ID A1F83G8C2ARO7P) to Germany (marketplace ID A1PA6795UKMFR9), the target marketplace ID is that of the UK, i.e., A1F83G8C2ARO7P. | ‘countryCode’: string The ID of the target marketplace. For example, when mapping data from the UK (marketplace ID A1F83G8C2ARO7P) to Germany (marketplace ID A1PA6795UKMFR9), the target marketplace ID is that of the UK, i.e., A1F83G8C2ARO7P. | } | ] | ‘requests’: list LocalizationTargetingExpressionRequest | [ | ‘LocalizationTargetingExpressionRequest’: dict | { | ‘isForNegativeTargeting’: bool Specifies whether the expression is for positive targeting (false) or negative targeting (true). | ‘expression’: LocalizationTargetingExpressionPredicate: dict | { | ‘type’: LocalizationTargetingExpressionPredicateType: string Targeting predicate type. The following predicate types are supported [ asinCategorySameAs, asinBrandSameAs, asinPriceLessThan, asinPriceBetween, asinPriceGreaterThan, asinReviewRatingLessThan, asinReviewRatingBetween, asinReviewRatingGreaterThan, asinSameAs, asinIsPrimeShippingEligible, asinAgeRangeSameAs, asinGenreSameAs ] | ‘value’: string The value of the predicate. Targeting expression syntax, including examples of predicates and the values they support, is documented here (https://advertising.amazon.com/API/docs/en-us/bulksheets/sp/sp-general-info/sp-product-attribute-targeting). Only predicates using the following types of data will be localized: | } | } | ] | ‘sourceDetails’: dict, LocalizationTargetingSourceDetails | { | ‘marketplaceId’: string The ID of the source marketplace. For example, when mapping data from the UK (marketplace ID A1F83G8C2ARO7P) to Germany (marketplace ID A1PA6795UKMFR9), the source marketplace ID is that of the UK, i.e., A1F83G8C2ARO7P. | ‘countryCode’: string A two-letter country code. Please refer to the table above for a list of supported country codes. | } }

### Example creating a dynamic dict based using MarketplacesIds for both source and target and predicate asinSameAs and version 1

import logging
from ad_api.api import Localization
from ad_api.base import AdvertisingApiException, MarketplacesIds

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s:%(levelname)s:%(message)s"
)


def get_targeting_expression(data: (str, dict), version: int = 1):
    try:

        result = Localization(debug=True).get_targeting_expression(
            version=version,
            body=data
        )

        logging.info(result)

    except AdvertisingApiException as error:
        logging.info(error)


if __name__ == '__main__':

    source_country_code = "GB"
    source_marketplace_id = MarketplacesIds[source_country_code].value

    target_country_code = "ES"
    target_marketplace_id = MarketplacesIds[target_country_code].value

    expression_request = \
        {
            "targetDetailsList": [
                {
                    "marketplaceId": target_marketplace_id,
                }
            ],
            "requests": [
                {
                    "targetingExpression": {
                        "isForNegativeTargeting": True,
                        "expression": [
                            {
                                "type": "asinSameAs",
                                "value": "B08SWH2KP4"
                            }
                        ]
                    }
                }
            ],
            "sourceDetails": {
                "marketplaceId": source_marketplace_id,
            }
        }

    get_targeting_expression(expression_request, version=1)

### Example result result_targeting_expression_v1.json

{
    "responses": [
        {
            "sourceTargetingExpression": {
                "expression": [{"value": "B08SWH2KP4", "type": "asinSameAs"}],
                "isForNegativeTargeting": true
            },
            "localizedTargetingExpressions": {
                "A1RKKUPIHCS9HS": {
                    "expression": [{"value": "B08SWH2KP4", "type": "asinSameAs"}],
                    "isForNegativeTargeting": true
                }
            },
            "localizedTargetingExpressionResults": {
                "A1RKKUPIHCS9HS": {
                    "localizedTargetingExpression": {
                        "expression": [{"value": "B08SWH2KP4", "type": "asinSameAs"}],
                        "isForNegativeTargeting": true
                    },
                    "status": "SUCCESS"
                }
            },
            "status": "SUCCESS"
        }
    ]
}

Download json the file to use

### Example when expression is not available (ASIN in this specific case)

{
    "responses": [
        {
            "sourceTargetingExpression": {
                "expression": [{"value": "B000000000", "type": "asinSameAs"}],
                "isForNegativeTargeting": true
            },
            "localizedTargetingExpressions": {},
            "localizedTargetingExpressionResults": {
                "A1RKKUPIHCS9HS": {
                    "status": "FAILURE",
                    "messages": [
                        "No match for ASIN B000000000 could be found in marketplace A1RKKUPIHCS9HS."
                    ],
                    "errorCode": "INTERNAL_ERROR"
                }
            },
            "status": "FAILURE",
            "errorCode": "INTERNAL_ERROR"
        }
    ]
}

### Example creating a dynamic dict based using countryCode for both source and target and predicate asinCategorySameAs and version 2

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

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s:%(levelname)s:%(message)s"
)


def get_targeting_expression(data: (str, dict), version: int = 1):
    try:

        result = Localization(debug=True).get_targeting_expression(
            version=version,
            body=data
        )

        logging.info(result)
        print (result.payload)

    except AdvertisingApiException as error:
        logging.info(error)

if __name__ == '__main__':

    source_country_code = "GB"
    target_country_code = "ES"

    expression_request = \
        {
            "targetDetailsList": [
                {
                    "countryCode": target_country_code,
                }
            ],
            "requests": [
                {
                    "targetingExpression": {
                        "isForNegativeTargeting": False,
                        "expression": [
                            {
                                "type": "asinCategorySameAs",
                                "value": "1730635031"
                            }
                        ]
                    }
                }
            ],
            "sourceDetails": {
                "countryCode": source_country_code,
            }
        }

    get_targeting_expression(expression_request, version=2)

### Example static result_targeting_expression_v2.json

{
    "responses": [
        {
            "sourceTargetingExpression": {
                "expression": [{"value": "1730635031", "type": "asinCategorySameAs"}],
                "isForNegativeTargeting": false
            },
            "localizedTargetingExpressions": {
                "ES": {
                    "expression": [
                        {"value": "1909320031", "type": "asinCategorySameAs"}
                    ],
                    "isForNegativeTargeting": false
                }
            },
            "localizedTargetingExpressionResults": {
                "ES": {
                    "localizedTargetingExpression": {
                        "expression": [
                            {"value": "1909320031", "type": "asinCategorySameAs"}
                        ],
                        "isForNegativeTargeting": false
                    },
                    "status": "SUCCESS"
                }
            },
            "status": "SUCCESS"
        }
    ]
}

Download json the file to use

### Example when expression is not available (category in this specific case)

{
    "responses": [
        {
            "sourceTargetingExpression": {
                "expression": [{"value": "1730635034", "type": "asinCategorySameAs"}],
                "isForNegativeTargeting": false
            },
            "localizedTargetingExpressions": {},
            "localizedTargetingExpressionResults": {
                "ES": {
                    "status": "FAILURE",
                    "messages": [
                        "There is no category node with the ID 1730635034 in the source marketplace A1F83G8C2ARO7P."
                    ],
                    "errorCode": "INTERNAL_ERROR"
                }
            },
            "status": "FAILURE",
            "errorCode": "INTERNAL_ERROR"
        }
    ]
}