ericblade/mws-advanced

Datatype: requestReports param MarketplaceIdList

pwrnrd opened this issue · 2 comments

The MWS API allows to request a report for a specific marketplace using "MarketplaceIdList". According to the MWS API documentation (https://docs.developer.amazonservices.com/en_ES/reports/Reports_RequestReport.html) the type should be: List of Type: xs:string.

In mws-advanced the variable MarketplaceIdList is specified to be of type: xs:string. How should MarketplaceIDList be specified?

I tried all of the following, but none of these specifications seem to work...

MarketplaceIdList: 'ATVPDKIKX0DER'
MarketplaceIdList: '[ATVPDKIKX0DER]'
MarketplaceIdList: 'MarketplaceIdList.Id.1=ATVPDKIKX0DER'
MarketplaceIdList: '[MarketplaceIdList.Id.1=ATVPDKIKX0DER]' 

I'm still learning how mws-advanced works under the hood... So I wrote something but I don't know whether it could be of any use:

const marketplaceIDs = ["ATVPDKIKX0DER", "A2EUQ1WTGCTBG2", "A1AM78C64UM0Y8"];

const getMarketplaceIDList = marketplaceIDs => {
	let i = 1;
	return marketplaceIDs
		.map(marketplaceID => `&MarketplaceIdList.Id.${i++}=${marketplaceID}`)
		.join("");
};

console.log(getMarketplaceIDList(marketplaceIDs));
// output: &MarketplaceIdList.Id.1=ATVPDKIKX0DER&MarketplaceIdList.Id.2=A2EUQ1WTGCTBG2&MarketplaceIdList.Id.3=A1AM78C64UM0Y8

The key take-away is that it takes an array of strings as input, which, in my opinion, makes more sense then a string value.

Yeah, I'm going to guess that either a- I wrote the validator for RequestReport before I wrote the Javascript Array <-> MWS List handler, or b- I made an error. :-)

In lib/endpoints/reports.js, find the RequestReport declaration, and under MarketplaceIdList, add:

list: 'MarketplaceIdList.Id'

and that should add it to the transformer. That is over in lib/validation.js (moving to lib/util/validation.js in the near future), around about line 149.

Then you can use

MarketplaceIdList: ['ATVPDKIKX0DER', ...]

Feel free to make a pull request, if you're able to test that and see that it works, it might be a few days before I get to it, pretty busy this week.