Getting started

Once you've installed your packages as described in the last section, you can start converting feeds. It's really simple.

Convert a feed file

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.

Convert a feed file from a string

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));

Feed-specific options

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.

(If you primarily sell outside the US and that merchant ID link doesn't work for you, try copying it and replacing sellercentral.amazon.com with the Seller Central URL that you usually use.)

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.

Last updated