bhushankummar / amazon-mws

Amazon MWS NodeJS Wrapper
MIT License
197 stars 78 forks source link

Settlement Report not parsing XML to JSON. #52

Closed charliecode closed 6 years ago

charliecode commented 6 years ago

Reports API, action: "GetReport", type: "_GET_V2_SETTLEMENT_REPORT_DATAXML" report does not parse the XML data to JSON. The issue is presenting itself in the "AmazonMwsResource.js" file inside function "processResponseType" on line 172 of version 0.0.19. It's seeing the content-type as "plain/text" although amazon is responding with XML data. The res.headers['content-type'] is showing as "plain/text". This is what's causing the problem because it causes the if statement on line 172 to fail which means the xml2js parser never runs. The "else" statement runs instead which tries to parse XML data using a CSV parser. If the same request is run through MWS scratchpad amazon responds with a res.headers['content-type'] of "text/xml" which is correct and would allow the XML2JS parser to run. Now sure if for some reason amazon is responding with the wrong content-type or if the content-type is accidentally being changed somewhere.

bhushankummar commented 6 years ago

@charliecode Strange! Internally we are not modifying any of headers or content-type.

charliecode commented 6 years ago

@bhushankumarl I know, it's very weird! I searched everywhere to see if it was somehow being manipulated. Makes no sense at all. Only thing I can think is maybe something being sent in the req is causing amazon to manipulate it before they send their response. Either that or it is totally on amazon's side, just weird since scratchpad get's the correct content-type returned. I went ahead and added additional code to the if statement which handles it, not sure if it's the best way to handle it but here it is. I'm willing to help with this project when I can just hesitant to do a pull request not knowing more about your library. Here it is. The addition is in bold. Line 172 of "AmazonMwsResource.js"

if (RESPONSE_CONTENT_TYPE.indexOf(res.headers['content-type'].toLowerCase()) > -1 || _.includes(responseString, '?xml'))

bhushankummar commented 6 years ago

@charliecode I have made changes according to it. Can you check against development branch?

charliecode commented 6 years ago

@bhushankumarl I just checked the development branch against both an XML and CSV content-type returned from amazon, all looks well and responds as expected. Looks like a good fix.

bhushankummar commented 6 years ago

@charliecode
It has been fixed and the version has been released. https://github.com/bhushankumarl/amazon-mws/releases/tag/v0.0.21

Please feel free to reopen if you still found any bug.