From 7f34b8c7997dc04fb06c5c31095a050026de3f3a Mon Sep 17 00:00:00 2001 From: taehyunlim Date: Wed, 21 Feb 2018 10:52:16 -0800 Subject: [PATCH 1/6] Added Merchant Fulfillment API operation to the list --- lib/amazon-mws.js | 5 +++-- lib/resources/MerchantFulfillment.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 lib/resources/MerchantFulfillment.js diff --git a/lib/amazon-mws.js b/lib/amazon-mws.js index e098e36..480a225 100644 --- a/lib/amazon-mws.js +++ b/lib/amazon-mws.js @@ -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'); @@ -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) { diff --git a/lib/resources/MerchantFulfillment.js b/lib/resources/MerchantFulfillment.js new file mode 100644 index 0000000..d9148da --- /dev/null +++ b/lib/resources/MerchantFulfillment.js @@ -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' + }) + +}); From f152662d350746909e979b27026d28990c243b06 Mon Sep 17 00:00:00 2001 From: taehyunlim Date: Wed, 21 Feb 2018 11:35:40 -0800 Subject: [PATCH 2/6] Updated MerchantFulfillment operation example snippet to the README markdown --- README.md | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 65e8142..46135bb 100644 --- a/README.md +++ b/README.md @@ -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 @@ -409,7 +482,7 @@ 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", @@ -417,4 +490,3 @@ Reference : http://docs.developer.amazonservices.com/en_CA/dev_guide/DG_Throttli } ``` Originally by [Bhushankumar Lilapara](https://github.com/bhushankumarl) (bhushankumar.lilapara@gmail.com). - From 6be9478c8d029ddcae508d00ebdf8e171d804608 Mon Sep 17 00:00:00 2001 From: BL Date: Mon, 26 Feb 2018 13:00:39 +0530 Subject: [PATCH 3/6] change the version --- CHANGELOG.md | 3 +++ examples/typeScript/package.json | 2 +- package.json | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ed049e..806aba0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +0.0.16 + - Added example of MerchantFulfillment + 0.0.15 - Bug fixed ResponseMetadata (RequestId) in success response - Added throttling details in non-xml response diff --git a/examples/typeScript/package.json b/examples/typeScript/package.json index fdea1bf..f2484ca 100644 --- a/examples/typeScript/package.json +++ b/examples/typeScript/package.json @@ -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": {} diff --git a/package.json b/package.json index f0abfce..bd36cbc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "amazon-mws", - "version": "0.0.15", + "version": "0.0.16", "description": "Amazon MWS API wrapper", "keywords": [ "Amazon MWS", From 2ca56d372b288b67709c8266ffdacc424194ed56 Mon Sep 17 00:00:00 2001 From: BL Date: Mon, 26 Feb 2018 15:07:03 +0530 Subject: [PATCH 4/6] Added example of merchantFulfillment --- .../merchantFulfillment/createShipment.js | 44 +++++++++++++++++++ .../getEligibleShippingServices.js | 43 ++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 examples/javaScript/merchantFulfillment/createShipment.js create mode 100644 examples/javaScript/merchantFulfillment/getEligibleShippingServices.js diff --git a/examples/javaScript/merchantFulfillment/createShipment.js b/examples/javaScript/merchantFulfillment/createShipment.js new file mode 100644 index 0000000..7cf23b5 --- /dev/null +++ b/examples/javaScript/merchantFulfillment/createShipment.js @@ -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(); \ No newline at end of file diff --git a/examples/javaScript/merchantFulfillment/getEligibleShippingServices.js b/examples/javaScript/merchantFulfillment/getEligibleShippingServices.js new file mode 100644 index 0000000..f2b9b4f --- /dev/null +++ b/examples/javaScript/merchantFulfillment/getEligibleShippingServices.js @@ -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(); \ No newline at end of file From 2e0cb7332c9a00962156f02d77fe283d2e089998 Mon Sep 17 00:00:00 2001 From: BL Date: Fri, 27 Apr 2018 12:43:50 +0530 Subject: [PATCH 5/6] parse CSV function debugging the delimiter error --- lib/AmazonMwsResource.js | 51 +++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/lib/AmazonMwsResource.js b/lib/AmazonMwsResource.js index 01951c4..f6ccb75 100644 --- a/lib/AmazonMwsResource.js +++ b/lib/AmazonMwsResource.js @@ -151,41 +151,48 @@ AmazonMwsResource.prototype = { } } - function processResponseType(res, response, callback) { + function parseCSVFile(res, responseString, callback) { + var data = []; + csv.fromString(responseString, {headers: true, delimiter: '\t', 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); - }); + parseCSVFile(res, responseString, callback); } } From 97918270c9a7da643244aa29bbf85077b3e7d447 Mon Sep 17 00:00:00 2001 From: BL Date: Thu, 10 May 2018 08:42:13 +0530 Subject: [PATCH 6/6] add support for both COMMA delimited csv files --- CHANGELOG.md | 2 ++ lib/AmazonMwsResource.js | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 806aba0..fd390b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ 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 diff --git a/lib/AmazonMwsResource.js b/lib/AmazonMwsResource.js index f6ccb75..c921b20 100644 --- a/lib/AmazonMwsResource.js +++ b/lib/AmazonMwsResource.js @@ -151,9 +151,9 @@ AmazonMwsResource.prototype = { } } - function parseCSVFile(res, responseString, callback) { + function parseCSVFile(res, responseString, delimiter, callback) { var data = []; - csv.fromString(responseString, {headers: true, delimiter: '\t', ignoreEmpty: true}) + csv.fromString(responseString, {headers: true, delimiter: delimiter, ignoreEmpty: true}) .on('data', function (value) { data.push(value); }) @@ -192,7 +192,23 @@ AmazonMwsResource.prototype = { return callback(null, items); } else { debug('It is NON-XML Response'); - parseCSVFile(res, responseString, callback); + 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.')); + } + } + } }