mws-advanced icon indicating copy to clipboard operation
mws-advanced copied to clipboard

Split listings reports requests for multiple marketplaces

Open pwrnrd opened this issue 5 years ago • 2 comments

Following the docs (see quote below), listings reports can only be requested per marketplace. It would be nice if MWS-Advanced is able to split a request for a listings report in multiple marketplaces in one request per marketplace.

If no MarketplaceId value is provided, reports that are not Listings Reports show all marketplaces the seller is registered in. You must specify a MarketplaceId value for Listings Reports.

Quote from: https://docs.developer.amazonservices.com/en_US/reports/Reports_UsingMultipleMarketplaces.html

Example code:

// Constant

const REPORTS_TO_REQUEST_BY_MARKETPLACE = [
	"_GET_FLAT_FILE_OPEN_LISTINGS_DATA_",
	"_GET_MERCHANT_LISTINGS_ALL_DATA_",
	"_GET_MERCHANT_LISTINGS_DATA_",
	"_GET_MERCHANT_LISTINGS_INACTIVE_DATA_",
	"_GET_MERCHANT_LISTINGS_DATA_BACK_COMPAT_",
	"_GET_MERCHANT_LISTINGS_DATA_LITE_",
	"_GET_MERCHANT_LISTINGS_DATA_LITER_",
	"_GET_MERCHANT_CANCELLED_LISTINGS_DATA_",
	"_GET_CONVERGED_FLAT_FILE_SOLD_LISTINGS_DATA_",
	"_GET_MERCHANT_LISTINGS_DEFECT_DATA_",
	"_GET_PAN_EU_OFFER_STATUS_",
	"_GET_MFN_PAN_EU_OFFER_STATUS_",
	"_GET_FLAT_FILE_GEO_OPPORTUNITIES_",
];

/**
 * Some reports must be requested by marketplace while others can be
 * requested for all marketplaces at once. If the report can only be
 * requested for one marketplace at a time, split the request. Otherwise,
 * simple return an array of the request object.
 * @param {Object} reportRequestParams
 * @return {Array.<object>}  reportRequestParams
 */
function splitRequestByMarketplaces(reportRequestParams) {
	const { ReportType, MarketplaceIdList } = reportRequestParams;
	if (
		REPORTS_TO_REQUEST_BY_MARKETPLACE.indexOf(ReportType) !== -1 &&
		MarketplaceIdList instanceof Array &&
		MarketplaceIdList.length > 0
	) {
		const splittedRequests = MarketplaceIdList.map(MarketplaceId => ({
			...reportRequestParams,
			MarketplaceIdList: [MarketplaceId],
		}));
		return splittedRequests;
	}

	// Return the object wrapped in an array to be consistent with the return of
	// the splitted requests
	return [reportRequestParams];
}

Since the request is splitted, the results should be stitched back together such that the form of what is returned by MWS-Advanced does not change. See also #105.

pwrnrd avatar Jan 02 '19 13:01 pwrnrd