Getting started
Last updated
Last updated
Once you've installed your packages as described in the last section, you can start converting feeds. It's really simple.
Say you want to convert your POST_PRODUCT_IMAGE_FEED
into a forward-compatible JSON format. Here's all you need to do:
use SellingPartnerApi\FeedTransformer\Transformer;
use SellingPartnerApi\FeedTransformer\FeedTypes\ProductImage;
$feedFile = 'path/to/your/feed.xml';
$json = Transformer::fromFile(
ProductImage::$feedType, // -> POST_PRODUCT_IMAGE_DATA
$feedPath,
'ATVPDKIKX0DER' // -> US Selling Partner API marketplace ID
);
$jsonFeedPath = 'path/to/new/feed.json';
file_put_contents($jsonFeedPath, json_encode($json));
The third parameter, marketplaceId
, should be a valid Selling Partner API marketplace ID (full list here) corresponding to the marketplace that you're uploading the feed to.
That's it! You can now upload the file at $jsonFeedPath
to Amazon the same way you were uploading your original feed, but replacing the original feed type (POST_PRODUCT_IMAGE_FEED
) with JSON_LISTINGS_FEED
in your request.
Instead of passing a file path to the converter, you can pass the feed contents to Converter::convertFromString()
instead:
use SellingPartnerApi\FeedTransformer\Transformer;
use SellingPartnerApi\FeedTransformer\FeedTypes\ProductImage;
$feedContents = '.....';
$json = Transformer::fromString(
ProductImage::$feedType, // -> POST_PRODUCT_IMAGE_DATA
$feedContents,
'ATVPDKIKX0DER' // -> US Selling Partner API marketplace ID
);
$jsonFeedPath = 'path/to/new/feed.json';
file_put_contents($jsonFeedPath, json_encode($json));
There's a fourth, optional argument to Converter::convert()
and Converter::convertFromString()
: an array of feed-type-specific parameters. Some feed types do not have any extra parameters, like the POST_PRODUCT_IMAGE_FEED
used in the example above
All flat file feed types require an extra merchantId
parameter. You can find your region-specific Amazon merchant ID here.
Here's what it looks like to pass feed-type-specific parameters:
use SellingPartnerApi\FeedTransformer\Transformer;
use SellingPartnerApi\FeedTransformer\FeedTypes\Invloader;
$feedFile = 'path/to/your/feed.xml';
$json = Transformer::fromFile(
Invloader::$feedType, // -> POST_FLAT_FILE_INVLOADER_DATA
$feedFile,
'ATVPDKIKX0DER',
['merchantId' => 'A2DI..........']
);
$jsonFeedPath = 'path/to/new/feed.json';
file_put_contents($jsonFeedPath, json_encode($json));
Feed-specific parameters are defined on the individual feed type documentation pages.