Skip to content

Commit

Permalink
Merge pull request #23 from bhushankumarl/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Bhushankumar L authored May 10, 2018
2 parents 9944010 + 9791827 commit 377562e
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.0.16
- Added example of MerchantFulfillment
- Added support for the comma delimiter report
- Added example of Comma delimiter report

0.0.15
- Bug fixed ResponseMetadata (RequestId) in success response
- Added throttling details in non-xml response
Expand Down
76 changes: 74 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,79 @@ var amazonMws = require('amazon-mws')('AWS_ACCESS_KEY_ID','AWS_SECRET_ACCESS_KEY
});
```

### MerchantFulfillment

#### Get Eligible Shipping Services
```js
amazonMws.merchantFulfillment.search({
'Version': '2015-06-01',
'Action': 'GetEligibleShippingServices',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'ShipmentRequestDetails.AmazonOrderId': 'AMAZON_ORDER_ID',
'ShipmentRequestDetails.PackageDimensions.Length': 'PACKAGE_LENGTH',
'ShipmentRequestDetails.PackageDimensions.Width': 'PACKAGE_WIDTH',
'ShipmentRequestDetails.PackageDimensions.Height': 'PACKAGE_HEIGHT',
'ShipmentRequestDetails.PackageDimensions.Unit': 'PACKAGE_UNIT',
'ShipmentRequestDetails.Weight.Value': 'WEIGHT_VALUE',
'ShipmentRequestDetails.Weight.Unit': 'WEIGHT_UNIT',
'ShipmentRequestDetails.ShipFromAddress.Name': 'SHIP_FROM_ADDRESS_NAME',
'ShipmentRequestDetails.ShipFromAddress.AddressLine1': 'SHIP_FROM_ADDRESS_LINE_1',
'ShipmentRequestDetails.ShipFromAddress.City': 'SHIP_FROM_ADDRESS_CITY',
'ShipmentRequestDetails.ShipFromAddress.StateOrProvinceCode': 'SHIP_FROM_ADDRESS_STATE_OR_PROVINCE_CODE',
'ShipmentRequestDetails.ShipFromAddress.PostalCode': 'SHIP_FROM_ADDRESS_POSTAL_CODE',
'ShipmentRequestDetails.ShipFromAddress.CountryCode': 'SHIP_FROM_ADDRESS_COUNTRY_CODE',
'ShipmentRequestDetails.ShipFromAddress.Email': 'SHIP_FROM_ADDRESS_EMAIL',
'ShipmentRequestDetails.ShipFromAddress.Phone': 'SHIP_FROM_ADDRESS_PHONE',
'ShipmentRequestDetails.ShippingServiceOptions.DeliveryExperience': 'DELIVERY_EXPERIENCE',
'ShipmentRequestDetails.ShippingServiceOptions.CarrierWillPickUp': 'CARRIER_WILL_PICKUP',
'ShipmentRequestDetails.ItemList.Item.1.OrderItemId': 'ORDER_ITEM_ID',
'ShipmentRequestDetails.ItemList.Item.1.Quantity': 'QUANTITY'
}, function (error, response) {
if (error) {
console.log('error ', error);
return;
}
console.log('response', response);
});
```
#### Create Shipment
```js
amazonMws.merchantFulfillment.create({
'Version': '2015-06-01',
'Action': 'CreateShipment',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'ShippingServiceId': 'SHIPPING_SERVICE_ID',
'ShipmentRequestDetails.AmazonOrderId': 'AMAZON_ORDER_ID',
'ShipmentRequestDetails.PackageDimensions.Length': 'PACKAGE_LENGTH',
'ShipmentRequestDetails.PackageDimensions.Width': 'PACKAGE_WIDTH',
'ShipmentRequestDetails.PackageDimensions.Height': 'PACKAGE_HEIGHT',
'ShipmentRequestDetails.PackageDimensions.Unit': 'PACKAGE_UNIT',
'ShipmentRequestDetails.Weight.Value': 'WEIGHT_VALUE',
'ShipmentRequestDetails.Weight.Unit': 'WEIGHT_UNIT',
'ShipmentRequestDetails.ShipFromAddress.Name': 'SHIP_FROM_ADDRESS_NAME',
'ShipmentRequestDetails.ShipFromAddress.AddressLine1': 'SHIP_FROM_ADDRESS_LINE_1',
'ShipmentRequestDetails.ShipFromAddress.City': 'SHIP_FROM_ADDRESS_CITY',
'ShipmentRequestDetails.ShipFromAddress.StateOrProvinceCode': 'SHIP_FROM_ADDRESS_STATE_OR_PROVINCE_CODE',
'ShipmentRequestDetails.ShipFromAddress.PostalCode': 'SHIP_FROM_ADDRESS_POSTAL_CODE',
'ShipmentRequestDetails.ShipFromAddress.CountryCode': 'SHIP_FROM_ADDRESS_COUNTRY_CODE',
'ShipmentRequestDetails.ShipFromAddress.Email': 'SHIP_FROM_ADDRESS_EMAIL',
'ShipmentRequestDetails.ShipFromAddress.Phone': 'SHIP_FROM_ADDRESS_PHONE',
'ShipmentRequestDetails.ShippingServiceOptions.DeliveryExperience': 'DELIVERY_EXPERIENCE',
'ShipmentRequestDetails.ShippingServiceOptions.CarrierWillPickUp': 'CARRIER_WILL_PICKUP',
'ShipmentRequestDetails.ItemList.Item.1.OrderItemId': 'ORDER_ITEM_ID',
'ShipmentRequestDetails.ItemList.Item.1.Quantity': 'QUANTITY'
}, function (error, response) {
if (error) {
console.log('error ', error);
return;
}
console.log('response', response);
});
```


### Orders

#### List Orders
Expand Down Expand Up @@ -409,12 +482,11 @@ var amazonMws = require('amazon-mws')('AWS_ACCESS_KEY_ID','AWS_SECRET_ACCESS_KEY
#### Additionally all api returns Throttling: Limits to how often you can submit requests
Reference : http://docs.developer.amazonservices.com/en_CA/dev_guide/DG_Throttling.html
```json
{
{
"x-mws-quota-max": "60.0",
"x-mws-quota-remaining": "38.0",
"x-mws-quota-resetson": "2017-12-08T08:21:00.000Z",
"x-mws-timestamp": "2017-12-08T07:52:15.567Z"
}
```
Originally by [Bhushankumar Lilapara](https://github.com/bhushankumarl) ([email protected]).

44 changes: 44 additions & 0 deletions examples/javaScript/merchantFulfillment/createShipment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'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 merchantFulfillmentRequest = function () {

amazonMws.merchantFulfillment.create({
'Version': '2015-06-01',
'Action': 'CreateShipment',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'ShippingServiceId': 'SHIPPING_SERVICE_ID',
'ShipmentRequestDetails.AmazonOrderId': 'AMAZON_ORDER_ID',
'ShipmentRequestDetails.PackageDimensions.Length': 'PACKAGE_LENGTH',
'ShipmentRequestDetails.PackageDimensions.Width': 'PACKAGE_WIDTH',
'ShipmentRequestDetails.PackageDimensions.Height': 'PACKAGE_HEIGHT',
'ShipmentRequestDetails.PackageDimensions.Unit': 'PACKAGE_UNIT',
'ShipmentRequestDetails.Weight.Value': 'WEIGHT_VALUE',
'ShipmentRequestDetails.Weight.Unit': 'WEIGHT_UNIT',
'ShipmentRequestDetails.ShipFromAddress.Name': 'SHIP_FROM_ADDRESS_NAME',
'ShipmentRequestDetails.ShipFromAddress.AddressLine1': 'SHIP_FROM_ADDRESS_LINE_1',
'ShipmentRequestDetails.ShipFromAddress.City': 'SHIP_FROM_ADDRESS_CITY',
'ShipmentRequestDetails.ShipFromAddress.StateOrProvinceCode': 'SHIP_FROM_ADDRESS_STATE_OR_PROVINCE_CODE',
'ShipmentRequestDetails.ShipFromAddress.PostalCode': 'SHIP_FROM_ADDRESS_POSTAL_CODE',
'ShipmentRequestDetails.ShipFromAddress.CountryCode': 'SHIP_FROM_ADDRESS_COUNTRY_CODE',
'ShipmentRequestDetails.ShipFromAddress.Email': 'SHIP_FROM_ADDRESS_EMAIL',
'ShipmentRequestDetails.ShipFromAddress.Phone': 'SHIP_FROM_ADDRESS_PHONE',
'ShipmentRequestDetails.ShippingServiceOptions.DeliveryExperience': 'DELIVERY_EXPERIENCE',
'ShipmentRequestDetails.ShippingServiceOptions.CarrierWillPickUp': 'CARRIER_WILL_PICKUP',
'ShipmentRequestDetails.ItemList.Item.1.OrderItemId': 'ORDER_ITEM_ID',
'ShipmentRequestDetails.ItemList.Item.1.Quantity': 'QUANTITY'
}, function (error, response) {
if (error) {
console.log('error ', error);
return;
}
console.log('response', response);
});
};

merchantFulfillmentRequest();
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'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 merchantFulfillmentRequest = function () {

amazonMws.merchantFulfillment.search({
'Version': '2015-06-01',
'Action': 'GetEligibleShippingServices',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'ShipmentRequestDetails.AmazonOrderId': 'AMAZON_ORDER_ID',
'ShipmentRequestDetails.PackageDimensions.Length': 'PACKAGE_LENGTH',
'ShipmentRequestDetails.PackageDimensions.Width': 'PACKAGE_WIDTH',
'ShipmentRequestDetails.PackageDimensions.Height': 'PACKAGE_HEIGHT',
'ShipmentRequestDetails.PackageDimensions.Unit': 'PACKAGE_UNIT',
'ShipmentRequestDetails.Weight.Value': 'WEIGHT_VALUE',
'ShipmentRequestDetails.Weight.Unit': 'WEIGHT_UNIT',
'ShipmentRequestDetails.ShipFromAddress.Name': 'SHIP_FROM_ADDRESS_NAME',
'ShipmentRequestDetails.ShipFromAddress.AddressLine1': 'SHIP_FROM_ADDRESS_LINE_1',
'ShipmentRequestDetails.ShipFromAddress.City': 'SHIP_FROM_ADDRESS_CITY',
'ShipmentRequestDetails.ShipFromAddress.StateOrProvinceCode': 'SHIP_FROM_ADDRESS_STATE_OR_PROVINCE_CODE',
'ShipmentRequestDetails.ShipFromAddress.PostalCode': 'SHIP_FROM_ADDRESS_POSTAL_CODE',
'ShipmentRequestDetails.ShipFromAddress.CountryCode': 'SHIP_FROM_ADDRESS_COUNTRY_CODE',
'ShipmentRequestDetails.ShipFromAddress.Email': 'SHIP_FROM_ADDRESS_EMAIL',
'ShipmentRequestDetails.ShipFromAddress.Phone': 'SHIP_FROM_ADDRESS_PHONE',
'ShipmentRequestDetails.ShippingServiceOptions.DeliveryExperience': 'DELIVERY_EXPERIENCE',
'ShipmentRequestDetails.ShippingServiceOptions.CarrierWillPickUp': 'CARRIER_WILL_PICKUP',
'ShipmentRequestDetails.ItemList.Item.1.OrderItemId': 'ORDER_ITEM_ID',
'ShipmentRequestDetails.ItemList.Item.1.Quantity': 'QUANTITY'
}, function (error, response) {
if (error) {
console.log('error ', error);
return;
}
console.log('response', response);
});
};

merchantFulfillmentRequest();
2 changes: 1 addition & 1 deletion examples/typeScript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@types/es6-promise": "0.0.33",
"babel-eslint": "^8.0.1",
"babel-preset-node6": "^11.0.0",
"amazon-mws": "^0.0.13",
"amazon-mws": "^0.0.16",
"node-expat": "^2.3.16"
},
"devDependencies": {}
Expand Down
67 changes: 45 additions & 22 deletions lib/AmazonMwsResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,41 +151,64 @@ AmazonMwsResource.prototype = {
}
}

function processResponseType(res, response, callback) {
function parseCSVFile(res, responseString, delimiter, callback) {
var data = [];
csv.fromString(responseString, {headers: true, delimiter: delimiter, ignoreEmpty: true})
.on('data', function (value) {
data.push(value);
})
.on('end', function () {
debug('response after parsing tab delimited file %o ', data);
var items = {};
items.data = data;
items.Headers = {
'x-mws-quota-max': res.headers['x-mws-quota-max'] || 'unknown',
'x-mws-quota-remaining': res.headers['x-mws-quota-remaining'] || 'unknown',
'x-mws-quota-resetson': res.headers['x-mws-quota-resetson'] || 'unknown',
'x-mws-timestamp': res.headers['x-mws-timestamp']
};
return callback(null, items);
})
.on('error', function (error) {
return callback(error);
});
}

function processResponseType(res, responseString, callback) {
//debug('response %o ', response);
//debug('res.headers %o ', res.headers);
if (RESPONSE_CONTENT_TYPE.indexOf(res.headers['content-type'].toLowerCase()) > -1) {
debug('It is XML Response');
response = xml2json.toJson(response);
var items = xml2json.toJson(responseString);
//debug('response after parsing JSON %o ', response);
response = JSON.parse(response);
response.Headers = {
items = JSON.parse(items);
items.Headers = {
'x-mws-quota-max': res.headers['x-mws-quota-max'] || 'unknown',
'x-mws-quota-remaining': res.headers['x-mws-quota-remaining'] || 'unknown',
'x-mws-quota-resetson': res.headers['x-mws-quota-resetson'] || 'unknown',
'x-mws-timestamp': res.headers['x-mws-timestamp']
};
//debug('after adding header response', response);
return callback(null, response);
return callback(null, items);
} else {
debug('It is NON-XML Response');
var data = [];
csv.fromString(response, {headers: true, delimiter: '\t'})
.on('data', function (value) {
data.push(value);
})
.on('end', function () {
debug('response after parsing tab delimited file %o ', data);
response = {};
response.data = data;
response.Headers = {
'x-mws-quota-max': res.headers['x-mws-quota-max'] || 'unknown',
'x-mws-quota-remaining': res.headers['x-mws-quota-remaining'] || 'unknown',
'x-mws-quota-resetson': res.headers['x-mws-quota-resetson'] || 'unknown',
'x-mws-timestamp': res.headers['x-mws-timestamp']
};
return callback(null, response);
});
var TAB_DELIMITER = '\t';
var COMMA_DELIMITER = ',';
try {
parseCSVFile(res, responseString, TAB_DELIMITER, callback);
} catch (Exception) {
debug('It is TAB_DELIMITER Exception ', Exception);
debug('Let us try to delimit using COMMA_DELIMITER');
try {
parseCSVFile(res, responseString, COMMA_DELIMITER, callback);
} catch (Exception) {
debug('It is COMMA_DELIMITER Exception ', Exception);
debug('Parsing using both TAB_DELIMITER & COMMA_DELIMITER Failed.');
debug('It may due to empty response or invalid request.');
return callback(new Error('Parsing fail.'));
}
}

}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/amazon-mws.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ var resources = {
sellers: require('./resources/Sellers'),
products: require('./resources/Products'),
orders: require('./resources/Orders'),
reports: require('./resources/Reports')
reports: require('./resources/Reports'),
merchantFulfillment: require('./resources/MerchantFulfillment')
};

AmazonMws.AmazonMwsResource = require('./AmazonMwsResource');
Expand Down Expand Up @@ -152,7 +153,7 @@ AmazonMws.prototype = {
cb(AmazonMws.USER_AGENT_SERIALIZED);
});
},

// Gets a JSON version of a User-Agent by encoding a seeded object and
// fetching a uname from the system.
getClientUserAgentSeeded: function (seed, cb) {
Expand Down
18 changes: 18 additions & 0 deletions lib/resources/MerchantFulfillment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

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

module.exports = AmazonMwsResource.extend({

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

create: amazonMwsMethod({
method: 'GET'
})

});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amazon-mws",
"version": "0.0.15",
"version": "0.0.16",
"description": "Amazon MWS API wrapper",
"keywords": [
"Amazon MWS",
Expand Down

0 comments on commit 377562e

Please sign in to comment.