jlevers / selling-partner-api

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

Parsing ProductTypes #767

Open franclin opened 1 month ago

franclin commented 1 month ago

Is it possible with this SDK to parse the productTypes returned by the getDefinitionsProductType operation?

misterakko commented 1 month ago

What do you need parsing? If $amazon->seller is what you got from calling SellingPartnerApi::seller() and $MARKETPLACE_ID is the code of the website where your merchandise is listed (e.g. Amazon Germany) then you do this

$ptdApi = $amazon->seller->ProductTypeDefinitionsV20200901();
$info = $ptdApi->getDefinitionsProductType (productType:'MEDICATION', marketplaceIds:[$MARKETPLACE_ID])->json();

$info is an array with two interesting things: (a) $info['schema']['link'] points to a JSON Schema file which describes what files you must send to offer your products in that marketplace (b) $info['propertyGroups'] lists by name all fields that Amazon will accept when describing the product.

franclin commented 1 month ago

What do you need parsing? If $amazon->seller is what you got from calling SellingPartnerApi::seller() and $MARKETPLACE_ID is the code of the website where your merchandice is listed (e.g. Amazon Germany) then you do this

$ptdApi = $amazon->seller->ProductTypeDefinitionsV20200901();
$info = $ptdApi->getDefinitionsProductType (productType:'MEDICATION', marketplaceIds:[$MARKETPLACE_ID])->json();

$info is an array with two interesting things: (a) $info['schema']['link'] points to a JSON Schema file which describes what files you must send to offer your products in that marketplace (b) $info['propertyGroups'] lists by name all fields that Amazon will accept when describing the product.

Hello @misterakko

Essentially I am looking for an implementation like this one: https://developer-docs.amazon.com/sp-api/docs/product-type-definition-meta-schema-v1-example-javascript in PHP.

Product Types are meant to be parsed to show required and optional fields that are to be provided in the JSON LISTING feed.

misterakko commented 1 month ago

Ah, OK, now I understand. Yes, that would be useful. No, the library does not do anything like that, AFAIK. For context, see the author's note at https://github.com/jlevers/selling-partner-api/issues/710

I have looked a bit into your problem — I'm trying to wrap my head around the absolute clusterfuck that is Amazon's move to JSON, and I guess you are doing the same. It seems to me that the JSON schema format is documented here: https://json-schema.org/draft/2019-09/release-notes If I'm right, than a PHP alternative to your JavaScript tool could be located here https://json-schema.org/implementations

If you find something promising, please leave a line here, I guess that could be useful to many.

franclin commented 1 month ago

Ah, OK, now I understand. Yes, that would be useful. No, the library does not do anything like that, AFAIK. For context, see the author's note at #710

I have looked a bit into your problem — I'm trying to wrap my head around the absolute clusterfuck that is Amazon's move to JSON, and I guess you are doing the same. It seems to me that the JSON schema format is documented here: https://json-schema.org/draft/2019-09/release-notes If I'm right, than a PHP alternative to your JavaScript tool could be located here https://json-schema.org/implementations

If you find something promising, please leave a line here, I guess that could be useful to many.

Great that you got my point. Indeed it stems from migrating from XML to JSON feeds. You are correct in your assessment that it seems to be a clusterfuck process overall.

The JSON schema implementation that you pointed out is not fit for purpose when it comes to Amazon Schema, looks like the only way to deal with it is to move another language where it is supported.

You are right to mention in Issue #710 that the new listing process seems like a rewrite of the Seller Central and seems to favour listing items 1x1 so scaling this approach to million items will be a nightmare.

So I am also looking for ways to overcome that challenge. One thing is for sure this library in its current form isn't the answer as far as I can tell.

jlevers commented 1 month ago

Depending on the feed type, I'm working on a (paid) tool that will allow you to input the old feeds and get out the proper JSON format for the new ones – an initial version should be ready in the next couple weeks.

franclin commented 1 month ago

Depending on the feed type, I'm working on a (paid) tool that will allow you to input the old feeds and get out the proper JSON format for the new ones – an initial version should be ready in the next couple weeks.

Thanks @jlevers looking forward to seeing it. Converting old XML feeds to their JSON versions isn't too difficult by the look of it.

What seems to be more intricate is the process of listing new items and including the correct data. This requires parsing complex JSON schemas and also it is unclear how this approach can scale.

jlevers commented 1 month ago

I've written a basic tool for that second part as well – I'll figure out a way to release it sometime soon. I don't think it's realistically possible to automate listing products of an arbitrary product type, because you need to know what information is required before you start the listing process, but I have a two-step process that parses the JSON schema and then generates a templated JSON file with all the attributes that need to be filled out.

franclin commented 1 month ago

Ok great looking forward to seeing it.

jlevers commented 1 week ago

@franclin the feed converter is now available, here: https://tools.highsidelabs.co

Hoping to have the product type schema parsing live in the next few weeks.

misterakko commented 1 week ago

I see no mention of POST_ORDER_FULFILLMENT_DATA in that page, should I worry?

jlevers commented 1 week ago

That feed type isn't being deprecated :) so you can keep using it as is

franclin commented 1 week ago

Thanks @jlevers will have a look at that.

By the way, I don't think that order related XML feeds are being deprecreated as per Deprecations.

The POST_ORDER_FULFILLMENT_DATA feed is very important to the order processing workflow. It is used to automatically flag an order as being shipped.

Thanks

jlevers commented 1 week ago

Yep, that's right – it's just the listing-related feeds that are being deprecated.