selling-partner-api icon indicating copy to clipboard operation
selling-partner-api copied to clipboard

CatalogItemsV20220401Api->searchCatalogItemsRequest() throws an exception with PHP 8.x

Open mdisimino opened this issue 2 years ago • 4 comments

While upgrading from PHP 7.x to 8.x, CatalogItemsV20220401Api->searchCatalogItemsRequest() throws the following exceptions:

Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in /workspace/vendor/jlevers/selling-partner-api/lib/Api/CatalogItemsV20220401Api.php:856 Stack trace: #0 /workspace/vendor/jlevers/selling-partner-api/lib/Api/CatalogItemsV20220401Api.php(856): count('A1RKKUPIHCS9HS') #1 /workspace/vendor/jlevers/selling-partner-api/lib/Api/CatalogItemsV20220401Api.php(529): SellingPartnerApi\Api\CatalogItemsV20220401Api->searchCatalogItemsRequest('A1RKKUPIHCS9HS', '0196432747160,0...', 'EAN', 'summaries, iden...', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) #2 /workspace/vendor/jlevers/selling-partner-api/lib/Api/CatalogItemsV20220401Api.php(503): SellingPartnerApi\Api\CatalogItemsV20220401Api->searchCatalogItemsWithHttpInfo('A1RKKUPIHCS9HS', '0196432747160,0...', 'EAN', 'summaries, iden...', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) #3 /workspace/a/workers.module.php(4562): SellingPartnerApi\Api\CatalogItemsV20220401Api->searchCatalogItems('A1RKKUPIHCS9HS', '0196432747160,0...', 'EAN', 'summaries, iden...', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)

mdisimino avatar Aug 03 '23 19:08 mdisimino

Based on the error, it looks like you're passing a single marketplace ID instead of an array of marketplace IDs.

jlevers avatar Aug 03 '23 20:08 jlevers

Hi jlevers, appreciate the swift response.

I am passing "A comma-delimited list of Amazon marketplace identifiers for the request" - I'm quoting the comment from the documentation [1] and not an array.

Even if using an array, the exact same exception is thrown.

[1] https://github.com/jlevers/selling-partner-api/blob/main/docs/Api/CatalogItemsV20220401Api.md

mdisimino avatar Aug 04 '23 10:08 mdisimino

After looking at the code, indeed there is nothing wrong with it.

It's just the instructions in the comments next to the arguments that are misleading: "string[] | A comma-delimited list of Amazon marketplace identifiers ..." "A comma-delimited list of product identifiers ..."

There is no "comma-delimited list", these are all arrays.

Thanks for your time.

mdisimino avatar Sep 11 '23 16:09 mdisimino

Got caught by this too. For anyone else -- both $identifiers and $marketplace_ids args expect arrays and not comma-delimited strings (and other arguments saying "comma-delimited list" for that matter).

Main gotcha comes from the fact that I already used getCatalogItem by sending it a single marketplace id string and it worked without issues, so I assumed that is the correct usage, but it actually only works by accident.

rossvor avatar Nov 03 '23 17:11 rossvor