Skip to content

Commit

Permalink
Merge pull request #4 from bhushankumarl/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Bhushankumar Lilapara authored Oct 25, 2017
2 parents 6d75466 + 13e2fa4 commit 7bac074
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.0.12
- Enhance SubmitFeed API
- Add GetFeedSubmissionResult Example
- Add FulfillmentOutboundShipment Feature
- Add List All Fulfillment Orders API

0.0.11
- ListInventorySupply Bug fix
- Add SubmitFeed API
Expand Down
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export DEBUG=MWS:*

## Usage

Run the DEBUG:

```bash
export AWS_ACCESS_KEY_ID=KEY
export AWS_SECRET_ACCESS_KEY=SECRET
Expand Down Expand Up @@ -79,6 +77,24 @@ var amazonMws = require('amazon-mws')('AWS_ACCESS_KEY_ID','AWS_SECRET_ACCESS_KEY
});
```

#### Get Feed Submission Result
```js
var FeedSubmissionId = '10101010XXX';
amazonMws.feeds.search({
'Version': '2009-01-01',
'Action': 'GetFeedSubmissionResult',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'FeedSubmissionId': FeedSubmissionId
}, function (error, response) {
if (error) {
console.log('error ', error);
return;
}
console.log('response', response);
});
```

### Finances

#### List Financial Event Groups
Expand Down Expand Up @@ -118,6 +134,26 @@ var amazonMws = require('amazon-mws')('AWS_ACCESS_KEY_ID','AWS_SECRET_ACCESS_KEY
});
```


### FulfillmentOutboundShipment

#### List All Fulfillment Orders
```js
amazonMws.fulfillmentOutboundShipment.search({
'Version': '2010-10-01',
'Action': 'ListAllFulfillmentOrders',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'QueryStartDateTime': new Date(13, 12, 2016)
}, function (error, response) {
if (error) {
console.log('error ', error);
return;
}
console.log('response', response);
});
```

### FulfillmentInventory

#### List Inventory Supply
Expand Down
26 changes: 26 additions & 0 deletions examples/feeds/getFeedSubmissionResult.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY';
var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET';

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

var feedRequest = function () {

var FeedSubmissionId = '10101010XXX';
amazonMws.feeds.search({
'Version': '2009-01-01',
'Action': 'GetFeedSubmissionResult',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'FeedSubmissionId': FeedSubmissionId
}, function (error, response) {
if (error) {
console.log('error ', error);
return;
}
console.log('response', response);
});
};

feedRequest();
25 changes: 25 additions & 0 deletions examples/fulfillmentOutboundShipment/listAllFulfillmentOrders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY';
var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET';

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

var fulfillmentOutboundShipmentRequest = function () {

amazonMws.fulfillmentOutboundShipment.search({
'Version': '2010-10-01',
'Action': 'ListAllFulfillmentOrders',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'QueryStartDateTime': new Date(13, 12, 2016)
}, function (error, response) {
if (error) {
console.log('error ', error);
return;
}
console.log('response', response);
});
};

fulfillmentOutboundShipmentRequest();
37 changes: 24 additions & 13 deletions lib/AmazonMwsResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,14 @@ AmazonMwsResource.prototype = {

function processResponseType(res, response, callback) {
debug('response %o ', response);
if (RESPONSE_CONTENT_TYPE.indexOf(res.headers['content-type']) > -1) {
if (RESPONSE_CONTENT_TYPE.indexOf(res.headers['content-type'].toLowerCase()) > -1) {
debug('It is XML Response');
response = xml2json.toJson(response);
debug('response after parsing JSON %o ', response);
response = JSON.parse(response);
return callback(null, response);
} else {
debug('It is NON-XML Response');
var data = [];
csv.fromString(response, {headers: true, delimiter: '\t'})
.on('data', function (value) {
Expand Down Expand Up @@ -204,16 +206,17 @@ AmazonMwsResource.prototype = {

var ResponseMetadata = {};
if (RESPONSE_CONTENT_TYPE.indexOf(res.headers['content-type']) > -1) {
debug('response Before Process %o ', JSON.stringify(response));
//debug('response Before Process %o ', JSON.stringify(response));
response = response[self.requestParamsJSON.Action + 'Response'];
ResponseMetadata = response.ResponseMetadata;
response = response[self.requestParamsJSON.Action + 'Result'];
response.ResponseMetadata = ResponseMetadata;
debug('response before %o ', JSON.stringify(response));
//debug('response before %o ', JSON.stringify(response));
processXml(response, 'update');
processXml(response, 'delete');
debug('response after Process %o ', JSON.stringify(response));
//debug('response after Process %o ', JSON.stringify(response));
}
debug('final response %o ', response);
// Expose res object
Object.defineProperty(response, 'lastResponse', {
enumerable: false,
Expand Down Expand Up @@ -261,7 +264,7 @@ AmazonMwsResource.prototype = {
var self = this;
//debug('path ', path);
self.requestParams = data;
self.body = {};
self.body = '';
if (!self.requestParams.Version) {
return callback.call(
self,
Expand All @@ -281,8 +284,11 @@ AmazonMwsResource.prototype = {
}

if (self.requestParams.Action === 'SubmitFeed') {
self.body.FeedContent = self.requestParams.FeedContent;
self.requestParams.ContentMD5Value = crypto.createHash('md5').update(qs.stringify(self.body)).digest('base64');
/*
* Use Feed Content without modify it as querystring for the SubmitFeed API
*/
self.body = self.requestParams.FeedContent;
self.requestParams.ContentMD5Value = crypto.createHash('md5').update(self.body).digest('base64');
delete self.requestParams.FeedContent;
}
//debug(' self.body %o ', self.body);
Expand All @@ -303,7 +309,10 @@ AmazonMwsResource.prototype = {

self.requestParamsJSON = _.clone(self.requestParams);
self.requestParams = qs.stringify(self.requestParams);
self.body = qs.stringify(self.body);
/*
* Use Feed Content without modify it as querystring for the SubmitFeed API
*/
//self.body = qs.stringify(self.body);

var headers = {
'Accept': 'text/xml',
Expand Down Expand Up @@ -338,11 +347,9 @@ AmazonMwsResource.prototype = {
};
params.path = params.path + '?' + self.requestParams;

//debug('params %o ', params);
//debug('body %o ', self.body);
var req = (
isInsecureConnection ? http : https
).request(params);
/*debug('params %o ', params);
debug('body %o ', self.body);*/
var req = (isInsecureConnection ? http : https).request(params);

req.setTimeout(timeout, self._timeoutHandler(timeout, req, callback));
req.on('response', self._responseHandler(req, callback));
Expand All @@ -351,6 +358,10 @@ AmazonMwsResource.prototype = {
req.on('socket', function (socket) {
socket.on((isInsecureConnection ? 'connect' : 'secureConnect'), function () {
// Send payload; we're safe:
//debug('body %o ', self.body);
/*
* Use Feed Content without modify it as querystring for the SubmitFeed API
*/
req.write(self.body);
req.end();
});
Expand Down
1 change: 1 addition & 0 deletions lib/amazon-mws.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var resources = {
feeds: require('./resources/Feeds'),
finances: require('./resources/Finances'),
fulfillmentInboundShipment: require('./resources/FulfillmentInboundShipment'),
fulfillmentOutboundShipment: require('./resources/FulfillmentOutboundShipment'),
fulfillmentInventory: require('./resources/FulfillmentInventory'),
sellers: require('./resources/Sellers'),
products: require('./resources/Products'),
Expand Down
14 changes: 14 additions & 0 deletions lib/resources/FulfillmentOutboundShipment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

var path = require('path');
var AmazonMwsResource = require('../AmazonMwsResource');
var amazonMwsMethod = AmazonMwsResource.method;

module.exports = AmazonMwsResource.extend({

path: 'FulfillmentOutboundShipment',
search: amazonMwsMethod({
method: 'GET'
})

});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "amazon-mws",
"version": "0.0.11",
"version": "0.0.12",
"description": "Amazon MWS API wrapper",
"keywords": [
"Amazon MWS",
"Amazon MWS Feeds",
"Amazon MWS Finances",
"Amazon MWS Fulfillment Inbound Shipment",
"Amazon MWS Fulfillment Outbound Shipment",
"Amazon MWS Fulfillment Inventory",
"Amazon MWS Orders",
"Amazon MWS Products",
Expand Down

0 comments on commit 7bac074

Please sign in to comment.