Skip to content

Commit 3779f7f

Browse files
author
BL
committed
add types for overriding responseType
1 parent f96d814 commit 3779f7f

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,7 @@ Originally by [Bhushankumar L](mailto:bhushankumar.lilapara@gmail.com).
722722
'Action': 'RequestReport',
723723
'SellerId': 'SELLER_ID',
724724
'MWSAuthToken': 'MWS_AUTH_TOKEN',
725-
'ReportType': '_GET_MERCHANT_LISTINGS_ALL_DATA_',
726-
'__RESPONSE_TYPE__': 'XML'
725+
'ReportType': '_GET_MERCHANT_LISTINGS_ALL_DATA_'
727726
}, function (error, response) {
728727
if (error) {
729728
console.log('error ', error);
@@ -793,13 +792,14 @@ Originally by [Bhushankumar L](mailto:bhushankumar.lilapara@gmail.com).
793792

794793
#### Request Report XML Response
795794
```
795+
amazonMws.setResponseFormat('XML');
796+
796797
amazonMws.reports.submit({
797798
'Version': '2009-01-01',
798799
'Action': 'RequestReport',
799800
'SellerId': 'SELLER_ID',
800801
'MWSAuthToken': 'MWS_AUTH_TOKEN',
801-
'ReportType': '_GET_MERCHANT_LISTINGS_ALL_DATA_',
802-
'__RESPONSE_TYPE__': 'XML'
802+
'ReportType': '_GET_MERCHANT_LISTINGS_ALL_DATA_'
803803
}, function (error, response) {
804804
if (error) {
805805
console.log('error ', error);

examples/javaScript/sample/requestReportXMLResponse.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET';
55

66
var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret);
77

8+
/**
9+
* This example has been written to override/set the default RESPONSE type to XML.
10+
*/
11+
812
var reportRequest = function () {
13+
amazonMws.setResponseFormat('XML');
14+
915
amazonMws.reports.submit({
1016
'Version': '2009-01-01',
1117
'Action': 'RequestReport',
1218
'SellerId': 'SELLER_ID',
1319
'MWSAuthToken': 'MWS_AUTH_TOKEN',
14-
'ReportType': '_GET_MERCHANT_LISTINGS_ALL_DATA_',
15-
'__RESPONSE_TYPE__': 'XML'
20+
'ReportType': '_GET_MERCHANT_LISTINGS_ALL_DATA_'
1621
}, function (error, response) {
1722
if (error) {
1823
console.log('error ', error);

index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ declare class Sellers extends BaseAmazonMWS {
6565
declare class Subscriptions extends BaseAmazonMWS {
6666

6767
create(params: any): Promise<any>;
68-
68+
6969
searchFor(params: any): Promise<any>;
7070

7171
remove(params: any): Promise<any>;
@@ -82,6 +82,8 @@ declare class AmazonMWS {
8282

8383
setHost(host?: string, port?: string, protocol?: string): void;
8484

85+
setResponseFormat(responseFormat: string): void;
86+
8587
feeds: Feeds;
8688

8789
finances: Finances;

lib/AmazonMwsResource.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,8 @@ AmazonMwsResource.prototype = {
406406
userCharset = data.__CHARSET__;
407407
delete data.__CHARSET__;
408408
}
409-
if (data.__RESPONSE_TYPE__) {
410-
responseType = data.__RESPONSE_TYPE__;
411-
delete data.__RESPONSE_TYPE__;
409+
if (self._AmazonMws.getApiField('format') !== 'JSON') {
410+
responseType = self._AmazonMws.getApiField('format');
412411
}
413412
self.requestParams = data;
414413

lib/amazon-mws.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
AmazonMws.DEFAULT_HOST = 'mws.amazonservices.com';
55
AmazonMws.DEFAULT_PORT = '443';
66
AmazonMws.DEFAULT_BASE_PATH = '/';
7-
AmazonMws.DEFAULT_RESPONSE_FORMAT = '.json';
7+
AmazonMws.DEFAULT_RESPONSE_FORMAT = 'JSON';
88
AmazonMws.DEFAULT_API_VERSION = null;
99

1010
// Use node's default timeout:
@@ -72,7 +72,7 @@ function AmazonMws(accessKey, accessSecret, version) {
7272
this._prepResources();
7373
this.setApiKey(accessKey, accessSecret);
7474
this.setApiVersion(version);
75-
this.setResponseFormat(AmazonMws.DEFAULT_RESPONSE_FORMAT);
75+
// this.setResponseFormat(AmazonMws.DEFAULT_RESPONSE_FORMAT);
7676
}
7777

7878
AmazonMws.prototype = {

0 commit comments

Comments
 (0)