amz_sp_api icon indicating copy to clipboard operation
amz_sp_api copied to clipboard

CatalogItems API is returning `MerchantFulfillment::Item` not `CatalogItems::Item`

Open evangelineMavrommati opened this issue 2 years ago • 4 comments

I'm making a request to get_catalog_item here

I have the debugging logger enabled and I can see that my request is returning a 200 with the appropriate data. However, the gem returns me the incorrect Item type. I am expected to be returned AmzSpApi::CatalogItemsApiModel::Item https://github.com/ericcj/amz_sp_api/blob/main/lib/catalog-items-api-model/docs/Item.md

Instead, I'm being returned a AmzSpApi::MerchantFulfillmentApiModel::Item https://github.com/ericcj/amz_sp_api/blob/main/lib/merchant-fulfillment-api-model/docs/Item.md

From what I can tell from debugging, this is due to the incorrect ApiClient.default being instantiated

Could anyone help me figure out how to fix this?

evangelineMavrommati avatar Mar 16 '23 17:03 evangelineMavrommati

it's brittle but you need to pass the api client into the initializer like this https://github.com/ericcj/amz_sp_api#getting-started

ericcj avatar Mar 17 '23 18:03 ericcj

hey @ericcj, appreciate your response!

After looking into this a bit more, it seems like this was were things were breaking down: https://github.com/ericcj/amz_sp_api/blob/84cd2dfc1398eee632da9b6f3ebfba25f591877a/lib/api_client.rb#L239

Think the ordering of the constants is not consistently guaranteed so that in conjunction with the detect was causing flakiness on which Item type was being returned

Since we're inheriting off AmzSpApi::ApiClient and not AmzSpApi::CatalogItemsApiModel::ApiClient, our solution was to be more explicit in the CatalogApi on the return type

We changed Item to 'AmzSpApi::CatalogItemsApiModel::Item' here https://github.com/ericcj/amz_sp_api/blob/84cd2dfc1398eee632da9b6f3ebfba25f591877a/lib/catalog-items-api-model/api/catalog_api.rb#L73

evangelineMavrommati avatar Mar 21 '23 15:03 evangelineMavrommati

I believe the same issue is happening with the ListingsApi. We are getting

`method_missing': undefined method `build_from_hash' for Item:Class (NoMethodError)

We also have a model called Item in our code base. I think it is calling that one. It should be scoped in the AmzSpApi code to the proper module.

philsmy avatar May 18 '23 15:05 philsmy

just encountered this as well. Also noticed that the PR https://github.com/spocket-co/amz_sp_api/pull/1 was reverted (maybe when the new version was generated?) - or maybe github is confusing me and this was never merged?

mreinsch avatar Dec 14 '23 12:12 mreinsch