saleweaver / python-amazon-sp-api

Python wrapper to access the amazon selling partner API
https://python-amazon-sp-api.readthedocs.io/en/latest/
MIT License
531 stars 234 forks source link

When using get_catalog_item and trying to get relationship the code fails. #1401

Closed simplyrahul closed 5 months ago

simplyrahul commented 5 months ago

Describe the bug When trying to get relationships for ASIN using get_catalog_item as per https://developer-docs.amazon.com/sp-api/docs/catalog-items-api-v2022-04-01-use-case-guide

Exact error: Traceback (most recent call last): File "D:\Python\AmzASINData.py", line 29, in asind = catalog.get_catalog_item(asin='ASIN',includedData='relationships') File "C:\Python\Python311\Lib\site-packages\sp_api\base\helpers.py", line 21, in wrapper return function(*args, **kwargs) File "C:\Python\Python311\Lib\site-packages\sp_api\api\catalog_items\catalog_items.py", line 93, in get_catalog_item return self._request(fill_query_params(kwargs.pop('path'), asin), params=kwargs) File "C:\Python\Python311\Lib\site-packages\sp_api\base\client.py", line 117, in _request return self._check_response(res, res_no_data, bulk, wrap_list) File "C:\Python\Python311\Lib\site-packages\sp_api\base\client.py", line 143, in _check_response raise exception(error, headers=res.headers) sp_api.base.exceptions.SellingApiBadRequestException: [{'code': 'InvalidInput', 'message': 'Request has missing or invalid parameters and cannot be parsed.', 'details': ''}]

To Reproduce Steps to reproduce the behavior: catalog = CatalogItems(credentials=credentials, marketplace=Marketplaces.IN) asind = catalog.get_catalog_item(asin='ASINENTEREDMANUALLY',includedData='relationships')

the code works when trying to get summaries or salesRanks, but fails for relationship

Expected behavior

I expect the relationship data for asin to be shown. I have made sure the ASIN I am using has a parent or is a child and have tested both and multiple parents.

Desktop (please complete the following information):

Additional context

None.

saleweaver commented 5 months ago

Are you the ASINs brand owner? Certain included data properties are only available to them, not sure about relationships though. If you can, test it with an asin that belongs to your brand.

There's quite a few issues with those endpoints and included data to be found on google, so it seems like the error is known to Amazon, but hasn't been fixed in the past two years.

My best recommendation is to add the info you have to one of the open issues under Amazon's repository, or create a new one. The library itself doesn't alter request nor response - Amazon will have to do something to fix this, I can't unfortunately.

simplyrahul commented 5 months ago

Yes, I am testing with ASIN for which I am the brand owner.

When I am using the service like boost.space and using the same credential I am able to get the relationships for the same ASIN. But the same credential and same ASIN gives the above error when using this library

I tested each parameter individually as per: https://developer-docs.amazon.com/sp-api/docs/catalog-items-api-v2022-04-01-use-case-guide

All these work: asin, attributes, dimensions, identifiers, images, productTypes, summaries, salesRanks

vendorDetails - Special access is needed and shows foribidden error.

Only thing that doesn't work is relationships

I am not sure it is relevant, but this is a screenshot from boost.space using same credential and same ASIN and showing the response I am getting. Screenshot_89

Edit: Sorry also dimensions are not working with this library

saleweaver commented 5 months ago

got it, that clears it. You are referencing the documentation for version 2022... but are using version 2020...

Try using the same version of the client as in the documentation, than it will work as expected, with the typing etc as in the relevant documentation.

To select a version for a client, use the version parameter in the client CatalogItems(credentials..., version=CatalogItemsVersion.V_2022_04_01)

simplyrahul commented 5 months ago

Oh yes. That is it. https://developer-docs.amazon.com/sp-api/docs/catalog-items-api-v2020-12-01-use-case-guide

After using variation, the old code worked.

However, after adding version=CatalogItemsVersion.V_2022_04_01 I get the error access denied for all includedData, do I need to make any changes to use the new version.

saleweaver commented 5 months ago

I don't know your credentials nor access level. Once you've checked that according to the documentation you'll be good to go.

rugved-bodke-stigya commented 5 months ago

I don't know your credentials nor access level. Once you've checked that according to the documentation you'll be good to go.

@saleweaver can you please give us a bit clear idea about proper credentials and access level? PS: getting the same problem

simplyrahul commented 5 months ago

@rugved-bodke-stigya

No additional access level is required from Amazon.

The following code additional changes worked for me. I am not including the entire code, just the additional changes that worked for me.

from sp_api.api import CatalogItems, CatalogItemsVersion

catalog = CatalogItems(credentials=credentials, marketplace=Marketplaces.IN,version=CatalogItemsVersion.V_2022_04_01) asind = catalog.get_catalog_item(asin='YOURASIN',includedData='relationships')

rugved-bodke-stigya commented 5 months ago

Thanks buddy, it actually works with specifying the version

simplyrahul commented 5 months ago

Yes, but you also need to import CatalogItemsVersion as well