Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CatalogItems API is returning MerchantFulfillment::Item not CatalogItems::Item #41

Open
evangelineMavrommati opened this issue Mar 16, 2023 · 4 comments

Comments

@evangelineMavrommati
Copy link

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?

@ericcj
Copy link
Owner

ericcj commented Mar 17, 2023

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

@evangelineMavrommati
Copy link
Author

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'

@philsmy
Copy link

philsmy commented May 18, 2023

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.

@mreinsch
Copy link
Contributor

mreinsch commented Dec 14, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants