ScaleLeap / amazon-mws-api-sdk

A fully typed TypeScript and Node.js Amazon MWS API Unofficial SDK
https://npm.im/@scaleleap/amazon-mws-api-sdk
MIT License
20 stars 12 forks source link

Get functions use incorrect http POST method #466

Open deni-skaraudio opened 3 years ago

deni-skaraudio commented 3 years ago

Hi there,

First I appreciate your contribution and how easy this library is to use.

I want to point out at two issues with the following functions inside FulfillmentInboundShipment class:

Example of code to reproduce the problem:

const inboundShipment = new FulfillmentInboundShipment(http);
const [response, meta] = await inboundShipment.getPrepInstructionsForAsin({
    ASINList: ['B07P7X96Z9'],
    ShipToCountryCode: 'US'
});
console.log(response);

Response I get from Amazon:

<ErrorResponse xmlns="http://mws.amazonaws.com/FulfillmentInboundShipment/2010-10-01/">
  <Error>
    <Type>Sender</Type>
    <Code>ValidationError</Code>
    <Message>1 validation error detected: Value null at 'asinList' failed to satisfy constraint: Member must not be null</Message>
  </Error>
  <RequestId>4db4ed4f-5f20-4449-ad8a-c9ef35395ade</RequestId>
</ErrorResponse>

The issue seems to be that the underlying http client is using POST instead of GET for such endpoints. I copied the above function's source code from lib\sections\fulfillment-inbound-shipment\fulfillment-inbound-shipment.js then changed the this.http.request param from POST to GET and ran it separately:

const [response, meta] = await http.request('GET', {   // was 'POST'
    resource: 'FulfillmentInboundShipment',
    version: '2010-10-01',
    action: 'GetPrepInstructionsForASIN',
    parameters: {
        'ASINList.Id': ['B07P7X96Z9'],
        ShipToCountryCode: 'US',
    },
});
console.log(response);

I got the right success response:

{
  GetPrepInstructionsForASINResponse: {
    attr: {
      xmlns: 'http://mws.amazonaws.com/FulfillmentInboundShipment/2010-10-01/'
    },
    GetPrepInstructionsForASINResult: { InvalidASINList: '', ASINPrepInstructionsList: [Object] },
    ResponseMetadata: { RequestId: '59248c00-b31e-40da-844c-16a72bfc5ee1' }
  }
}

I stumbled upon these two while using your module, but this could be the case for more GET methods.

Cheers, Deni

moltar commented 3 years ago

Hey Deni, thanks for raising this issue.

Would you be able to contribute a fix via PR?

deni-skaraudio commented 2 years ago

Hi @moltar am quite overloaded currently, sorry.