ericcj/amz_sp_api

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

evangelineMavrommati opened this issue · 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?

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

hey @ericcj, appreciate your response!

After looking into this a bit more, it seems like this was were things were breaking down:

AmzSpApi.constants.map{|c| AmzSpApi.const_get(c)}.select{|sub| sub.kind_of?(Module)}.detect{|sub| sub.const_defined?(return_type)}.const_get(return_type).build_from_hash(data)

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

return_type = opts[:return_type] || 'Item'

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.

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