Why does python gives an error when running this function?

262 Views Asked by At

I am trying to run the get_item_offers_batch() function from the python amazon sp api: https://python-amazon-sp-api.readthedocs.io/en/latest/endpoints/products/#sp_api.api.Products.get_item_offers_batch

However I am getting the following error when the function runs in python: sp_api.base.exceptions.SellingApiBadRequestException: [{'code': 'InvalidInput', 'message': 'InvalidInput', 'details': ''}]

Here is my code

request = [dict(asin="B08CGT4FXL", MarketplaceId="A1PA6795UKMFR9", item_condition='new'), dict(asin="B07KF8LPBC", MarketplaceId="A1PA6795UKMFR9", item_condition='new')]
res = Products(credentials=client_config, marketplace=Marketplaces.DE).get_item_offers_batch(requests_=request)
print(res.payload)

It asks for a List of dictionaries, which I have provided

What could be the issue ?

Required parameters

Tried to rung the python sp api batch function and the script crashes with invalid input code.

1

There are 1 best solutions below

0
On

It's a bit confusing you basically have to use the uri of the endpoint instead of the asin. Which should look something like this:

from sp_api.api import Products

client = Products(
        credentials=credentials,
        marketplace=Marketplaces.DE,
    )

res = client.get_item_offers_batch([
        {
            'uri': '/products/pricing/v0/items/B08CGT4FXL/offers',
            'method': 'GET',
            'ItemCondition':'New',
            'MarketplaceId':"A1PA6795UKMFR9"
        }
    ]
    )
    print(res.payload)  # json data
except SellingApiException as ex:
    print(ex)

Hope that helps.