Validation
There are often differences – sometimes minor, sometimes substantial – between the required fields in the existing XML and flat file feeds, and the required fields in the new JSON feed. This is particularly true when working with the POST_PRODUCT_DATA
and POST_FLAT_FILE_LISTINGS_DATA
feed types, where the feed attributes vary substantially depending on the product type being created. The new JSON-based feed typically has many more requirements for a given product type than the older product feeds.
To help you manage this, we've built two validators that you can run the converted feed data through to check if there are attributes that are missing or invalid. The validators can point you to the exact XML tag or flat file field you need to add or modify, and in some cases, the validators can fix the errors without any further intervention on your part.
Before submitting a POST_PRODUCT_DATA
or POST_FLAT_FILE_LISTINGS_DATA
feed for the first time for a given product type, we highly recommend first running a sample feed with only a few products through the two validators, to check if you need to make any changes before you start converting feeds in bulk.
Installation
This section assumes that you already have the Highside Labs private Composer repository configured, as described in Installation.
The validator classes are in a separate package from the rest of the feed transformer, because they are the one part of the tool that requires PHP 8.2+ instead of PHP 7.1+. To install the package, run:
Validators
There are two validator classes, JsonSchemaValidator
and AmazonValidator.
They share an interface. When testing, we recommend starting with the JsonSchemaValidator
and moving on to the AmazonValidator
after fixing any errors caught by the JsonSchemaValidator
, because the AmazonValidator
makes actual requests to the Selling Partner API on your behalf.
JSON Schema Validator
This validator checks the converted feed data against Amazon's JSON Schema for the product type that's being sent in your feed. Each product type has its own specific JSON Schema, which the validator will fetch from the Selling Partner API for you. It will then fix any validation issues that it's able to resolve on its own, and return an array of issues that you need to handle, if there are any.
Here's what that looks like in practice:
Because the JsonSchemaValidator
can and will modify the JSON data in order to fix validation errors, call the JsonSchemaValidator::changes()
method after your first time using the validator for a particular product type. If it returns a list of messages describing changes it has made to the JSON data, you should run every converted feed for that product type through the JsonSchemaValidator
to make sure it makes the necessary fixes before you submit the converted feed to Amazon.
If for any reason you don't want the validator to modify your converted feed data in order to fix it, pass ['fix' ⇒ false]
as the third parameter to JsonSchemaValidator::validate()
.
If there are validation errors that the validator can't fix, the validation error messages should make it pretty clear what you need to change. Often you will need to add a particular field or tag, and the name of the field/tag usually makes it pretty self-explanatory what the value should be. If it's unclear what data you need to add, just shoot us an email and we'll help you get it sorted out.
Amazon Validator
Once your data is running through the JsonSchemaValidator
cleanly, you can use the AmazonValidator
to confirm that Amazon will accept your data. This validator actually submits the feed data to Amazon in validation-only mode, so the contents of the feed won't affect your listings in any way. The rate limit for validation-only mode is quite low, so we do not recommend validating feeds of more than 5 items at a time, as you will likely run into rate limits. This validator is only meant for testing a feed for a particular product type, not for ongoing use in production.
The AmazonValidator
's interface is the same as the JsonSchemaValidator
's, so usage looks basically identical:
Fixing validation errors
Validation errors are returned as a map of SKUs to SKU-specific errors. They look something like this (these are errors from a POST_PRODUCT_FEED
for the SHOES
product type):
This tells you that you need to add the following data to your POST_PRODUCT_DATA
feed, in addition to whatever tags are already in there:
You may need to go through a few rounds of feed format modification and re-validation to complete all the new required fields.
Xpaths in validation error messages
Note that occasionally, the Xpath specified in a validation error may seem unrelated to the product type you're working with. This is because there are often many similar Xpaths that map to the same JSON field in the converted feed, and sometimes the transformer will be unable to determine which of the multiple Xpaths is most closely related to the product type you're working with. Even though the Xpath may seem wrong, it will still be converted to the correct product attribute in the converted feed.
For instance, this validation error could be returned when validating a converted POST_PRODUCT_TYPE
feed:
Even though the Message/Product/ProductData/Sports
tag probably would not normally be present in SHOES
product feeds, specifying the Message/Product/ProductData/Sports/FabricType
tag will still fix the validation error and ensure your feed has all the data that Amazon requires.
Last updated