jlevers / selling-partner-api

A PHP client library for Amazon's Selling Partner API
BSD 3-Clause "New" or "Revised" License
397 stars 185 forks source link

searchCatalogItems returns a 403 Forbidden response #683

Closed misterakko closed 1 month ago

misterakko commented 5 months ago

name: searchCatalogItems returns a 403 Forbidden response about: API call which worked under v5 of the library fails under v6.0.4 title: '' labels: '' assignees: ''


Problem description:

I am porting my code from v5 to v6 of the library, line by line. It's mostly boring work, and I found no issues worth of the name but this.

The snippet of code I'm pasting just looks for an item by EAN in the Amazon catalog. It works under v5. v5 code:

$amazon = new SaratAmazon($db); // initializes everything
$catApi = new SellingPartnerApi\Api\CatalogItemsV20201201Api($amazon->myConfig);
$answers = $catApi->searchCatalogItems('8804777427',
   array($amazon->prefs['amazon-MARKETPLACE_ID']),
   'salesRanks,identifiers,summaries')->getItems();

Error:

Client error: `GET https://sellingpartnerapi-eu.amazon.com/catalog/2022-04-01/items?marketplaceIds=8804777427&identifiers=APJ6JRA9NG5V4&identifiersType=salesRanks%2Cidentifiers%2Csummaries` resulted in a `403 Forbidden` response

Code

$amazon = new SaratAmazon($db); // calls ->make()->seller()
$catApi = $amazon->mySeller->catalogItems();
$answers = $catApi->searchCatalogItems(
   array('8804777427'),
   array($amazon->prefs['amazon-MARKETPLACE_ID']),
   'salesRanks,identifiers,summaries');
jlevers commented 3 months ago

Does this work for you? I think you have some arguments out of order, and the csv string changed to an array.

$answers = $catApi->searchCatalogItems(
    marketplaceIds: [$amazon->prefs['amazon-MARKETPLACE_ID']],
    identifiers: ['8804777427'],
    includedData: ['salesRanks', 'identifiers', 'summaries']
);
misterakko commented 1 month ago

You are right. And: I will, starting from now, start to explicitly state the name of the parameter for every API call, because many need a bazillion and it's way too simple to mix things (PHPStorms helps but does not solve the issue, at least in my case).

Thanks!