Skip to content

Commit 377562e

Browse files
author
Bhushankumar L
authored
Merge pull request #23 from bhushankumarl/development
Development
2 parents 9944010 + 9791827 commit 377562e

File tree

9 files changed

+234
-28
lines changed

9 files changed

+234
-28
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.0.16
2+
- Added example of MerchantFulfillment
3+
- Added support for the comma delimiter report
4+
- Added example of Comma delimiter report
5+
16
0.0.15
27
- Bug fixed ResponseMetadata (RequestId) in success response
38
- Added throttling details in non-xml response

README.md

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,79 @@ var amazonMws = require('amazon-mws')('AWS_ACCESS_KEY_ID','AWS_SECRET_ACCESS_KEY
214214
});
215215
```
216216

217+
### MerchantFulfillment
218+
219+
#### Get Eligible Shipping Services
220+
```js
221+
amazonMws.merchantFulfillment.search({
222+
'Version': '2015-06-01',
223+
'Action': 'GetEligibleShippingServices',
224+
'SellerId': 'SELLER_ID',
225+
'MWSAuthToken': 'MWS_AUTH_TOKEN',
226+
'ShipmentRequestDetails.AmazonOrderId': 'AMAZON_ORDER_ID',
227+
'ShipmentRequestDetails.PackageDimensions.Length': 'PACKAGE_LENGTH',
228+
'ShipmentRequestDetails.PackageDimensions.Width': 'PACKAGE_WIDTH',
229+
'ShipmentRequestDetails.PackageDimensions.Height': 'PACKAGE_HEIGHT',
230+
'ShipmentRequestDetails.PackageDimensions.Unit': 'PACKAGE_UNIT',
231+
'ShipmentRequestDetails.Weight.Value': 'WEIGHT_VALUE',
232+
'ShipmentRequestDetails.Weight.Unit': 'WEIGHT_UNIT',
233+
'ShipmentRequestDetails.ShipFromAddress.Name': 'SHIP_FROM_ADDRESS_NAME',
234+
'ShipmentRequestDetails.ShipFromAddress.AddressLine1': 'SHIP_FROM_ADDRESS_LINE_1',
235+
'ShipmentRequestDetails.ShipFromAddress.City': 'SHIP_FROM_ADDRESS_CITY',
236+
'ShipmentRequestDetails.ShipFromAddress.StateOrProvinceCode': 'SHIP_FROM_ADDRESS_STATE_OR_PROVINCE_CODE',
237+
'ShipmentRequestDetails.ShipFromAddress.PostalCode': 'SHIP_FROM_ADDRESS_POSTAL_CODE',
238+
'ShipmentRequestDetails.ShipFromAddress.CountryCode': 'SHIP_FROM_ADDRESS_COUNTRY_CODE',
239+
'ShipmentRequestDetails.ShipFromAddress.Email': 'SHIP_FROM_ADDRESS_EMAIL',
240+
'ShipmentRequestDetails.ShipFromAddress.Phone': 'SHIP_FROM_ADDRESS_PHONE',
241+
'ShipmentRequestDetails.ShippingServiceOptions.DeliveryExperience': 'DELIVERY_EXPERIENCE',
242+
'ShipmentRequestDetails.ShippingServiceOptions.CarrierWillPickUp': 'CARRIER_WILL_PICKUP',
243+
'ShipmentRequestDetails.ItemList.Item.1.OrderItemId': 'ORDER_ITEM_ID',
244+
'ShipmentRequestDetails.ItemList.Item.1.Quantity': 'QUANTITY'
245+
}, function (error, response) {
246+
if (error) {
247+
console.log('error ', error);
248+
return;
249+
}
250+
console.log('response', response);
251+
});
252+
```
253+
#### Create Shipment
254+
```js
255+
amazonMws.merchantFulfillment.create({
256+
'Version': '2015-06-01',
257+
'Action': 'CreateShipment',
258+
'SellerId': 'SELLER_ID',
259+
'MWSAuthToken': 'MWS_AUTH_TOKEN',
260+
'ShippingServiceId': 'SHIPPING_SERVICE_ID',
261+
'ShipmentRequestDetails.AmazonOrderId': 'AMAZON_ORDER_ID',
262+
'ShipmentRequestDetails.PackageDimensions.Length': 'PACKAGE_LENGTH',
263+
'ShipmentRequestDetails.PackageDimensions.Width': 'PACKAGE_WIDTH',
264+
'ShipmentRequestDetails.PackageDimensions.Height': 'PACKAGE_HEIGHT',
265+
'ShipmentRequestDetails.PackageDimensions.Unit': 'PACKAGE_UNIT',
266+
'ShipmentRequestDetails.Weight.Value': 'WEIGHT_VALUE',
267+
'ShipmentRequestDetails.Weight.Unit': 'WEIGHT_UNIT',
268+
'ShipmentRequestDetails.ShipFromAddress.Name': 'SHIP_FROM_ADDRESS_NAME',
269+
'ShipmentRequestDetails.ShipFromAddress.AddressLine1': 'SHIP_FROM_ADDRESS_LINE_1',
270+
'ShipmentRequestDetails.ShipFromAddress.City': 'SHIP_FROM_ADDRESS_CITY',
271+
'ShipmentRequestDetails.ShipFromAddress.StateOrProvinceCode': 'SHIP_FROM_ADDRESS_STATE_OR_PROVINCE_CODE',
272+
'ShipmentRequestDetails.ShipFromAddress.PostalCode': 'SHIP_FROM_ADDRESS_POSTAL_CODE',
273+
'ShipmentRequestDetails.ShipFromAddress.CountryCode': 'SHIP_FROM_ADDRESS_COUNTRY_CODE',
274+
'ShipmentRequestDetails.ShipFromAddress.Email': 'SHIP_FROM_ADDRESS_EMAIL',
275+
'ShipmentRequestDetails.ShipFromAddress.Phone': 'SHIP_FROM_ADDRESS_PHONE',
276+
'ShipmentRequestDetails.ShippingServiceOptions.DeliveryExperience': 'DELIVERY_EXPERIENCE',
277+
'ShipmentRequestDetails.ShippingServiceOptions.CarrierWillPickUp': 'CARRIER_WILL_PICKUP',
278+
'ShipmentRequestDetails.ItemList.Item.1.OrderItemId': 'ORDER_ITEM_ID',
279+
'ShipmentRequestDetails.ItemList.Item.1.Quantity': 'QUANTITY'
280+
}, function (error, response) {
281+
if (error) {
282+
console.log('error ', error);
283+
return;
284+
}
285+
console.log('response', response);
286+
});
287+
```
288+
289+
217290
### Orders
218291

219292
#### List Orders
@@ -409,12 +482,11 @@ var amazonMws = require('amazon-mws')('AWS_ACCESS_KEY_ID','AWS_SECRET_ACCESS_KEY
409482
#### Additionally all api returns Throttling: Limits to how often you can submit requests
410483
Reference : http://docs.developer.amazonservices.com/en_CA/dev_guide/DG_Throttling.html
411484
```json
412-
{
485+
{
413486
"x-mws-quota-max": "60.0",
414487
"x-mws-quota-remaining": "38.0",
415488
"x-mws-quota-resetson": "2017-12-08T08:21:00.000Z",
416489
"x-mws-timestamp": "2017-12-08T07:52:15.567Z"
417490
}
418491
```
419492
Originally by [Bhushankumar Lilapara](https://github.com/bhushankumarl) (bhushankumar.lilapara@gmail.com).
420-
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY';
4+
var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET';
5+
6+
var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret);
7+
8+
var merchantFulfillmentRequest = function () {
9+
10+
amazonMws.merchantFulfillment.create({
11+
'Version': '2015-06-01',
12+
'Action': 'CreateShipment',
13+
'SellerId': 'SELLER_ID',
14+
'MWSAuthToken': 'MWS_AUTH_TOKEN',
15+
'ShippingServiceId': 'SHIPPING_SERVICE_ID',
16+
'ShipmentRequestDetails.AmazonOrderId': 'AMAZON_ORDER_ID',
17+
'ShipmentRequestDetails.PackageDimensions.Length': 'PACKAGE_LENGTH',
18+
'ShipmentRequestDetails.PackageDimensions.Width': 'PACKAGE_WIDTH',
19+
'ShipmentRequestDetails.PackageDimensions.Height': 'PACKAGE_HEIGHT',
20+
'ShipmentRequestDetails.PackageDimensions.Unit': 'PACKAGE_UNIT',
21+
'ShipmentRequestDetails.Weight.Value': 'WEIGHT_VALUE',
22+
'ShipmentRequestDetails.Weight.Unit': 'WEIGHT_UNIT',
23+
'ShipmentRequestDetails.ShipFromAddress.Name': 'SHIP_FROM_ADDRESS_NAME',
24+
'ShipmentRequestDetails.ShipFromAddress.AddressLine1': 'SHIP_FROM_ADDRESS_LINE_1',
25+
'ShipmentRequestDetails.ShipFromAddress.City': 'SHIP_FROM_ADDRESS_CITY',
26+
'ShipmentRequestDetails.ShipFromAddress.StateOrProvinceCode': 'SHIP_FROM_ADDRESS_STATE_OR_PROVINCE_CODE',
27+
'ShipmentRequestDetails.ShipFromAddress.PostalCode': 'SHIP_FROM_ADDRESS_POSTAL_CODE',
28+
'ShipmentRequestDetails.ShipFromAddress.CountryCode': 'SHIP_FROM_ADDRESS_COUNTRY_CODE',
29+
'ShipmentRequestDetails.ShipFromAddress.Email': 'SHIP_FROM_ADDRESS_EMAIL',
30+
'ShipmentRequestDetails.ShipFromAddress.Phone': 'SHIP_FROM_ADDRESS_PHONE',
31+
'ShipmentRequestDetails.ShippingServiceOptions.DeliveryExperience': 'DELIVERY_EXPERIENCE',
32+
'ShipmentRequestDetails.ShippingServiceOptions.CarrierWillPickUp': 'CARRIER_WILL_PICKUP',
33+
'ShipmentRequestDetails.ItemList.Item.1.OrderItemId': 'ORDER_ITEM_ID',
34+
'ShipmentRequestDetails.ItemList.Item.1.Quantity': 'QUANTITY'
35+
}, function (error, response) {
36+
if (error) {
37+
console.log('error ', error);
38+
return;
39+
}
40+
console.log('response', response);
41+
});
42+
};
43+
44+
merchantFulfillmentRequest();
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY';
4+
var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET';
5+
6+
var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret);
7+
8+
var merchantFulfillmentRequest = function () {
9+
10+
amazonMws.merchantFulfillment.search({
11+
'Version': '2015-06-01',
12+
'Action': 'GetEligibleShippingServices',
13+
'SellerId': 'SELLER_ID',
14+
'MWSAuthToken': 'MWS_AUTH_TOKEN',
15+
'ShipmentRequestDetails.AmazonOrderId': 'AMAZON_ORDER_ID',
16+
'ShipmentRequestDetails.PackageDimensions.Length': 'PACKAGE_LENGTH',
17+
'ShipmentRequestDetails.PackageDimensions.Width': 'PACKAGE_WIDTH',
18+
'ShipmentRequestDetails.PackageDimensions.Height': 'PACKAGE_HEIGHT',
19+
'ShipmentRequestDetails.PackageDimensions.Unit': 'PACKAGE_UNIT',
20+
'ShipmentRequestDetails.Weight.Value': 'WEIGHT_VALUE',
21+
'ShipmentRequestDetails.Weight.Unit': 'WEIGHT_UNIT',
22+
'ShipmentRequestDetails.ShipFromAddress.Name': 'SHIP_FROM_ADDRESS_NAME',
23+
'ShipmentRequestDetails.ShipFromAddress.AddressLine1': 'SHIP_FROM_ADDRESS_LINE_1',
24+
'ShipmentRequestDetails.ShipFromAddress.City': 'SHIP_FROM_ADDRESS_CITY',
25+
'ShipmentRequestDetails.ShipFromAddress.StateOrProvinceCode': 'SHIP_FROM_ADDRESS_STATE_OR_PROVINCE_CODE',
26+
'ShipmentRequestDetails.ShipFromAddress.PostalCode': 'SHIP_FROM_ADDRESS_POSTAL_CODE',
27+
'ShipmentRequestDetails.ShipFromAddress.CountryCode': 'SHIP_FROM_ADDRESS_COUNTRY_CODE',
28+
'ShipmentRequestDetails.ShipFromAddress.Email': 'SHIP_FROM_ADDRESS_EMAIL',
29+
'ShipmentRequestDetails.ShipFromAddress.Phone': 'SHIP_FROM_ADDRESS_PHONE',
30+
'ShipmentRequestDetails.ShippingServiceOptions.DeliveryExperience': 'DELIVERY_EXPERIENCE',
31+
'ShipmentRequestDetails.ShippingServiceOptions.CarrierWillPickUp': 'CARRIER_WILL_PICKUP',
32+
'ShipmentRequestDetails.ItemList.Item.1.OrderItemId': 'ORDER_ITEM_ID',
33+
'ShipmentRequestDetails.ItemList.Item.1.Quantity': 'QUANTITY'
34+
}, function (error, response) {
35+
if (error) {
36+
console.log('error ', error);
37+
return;
38+
}
39+
console.log('response', response);
40+
});
41+
};
42+
43+
merchantFulfillmentRequest();

examples/typeScript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"@types/es6-promise": "0.0.33",
99
"babel-eslint": "^8.0.1",
1010
"babel-preset-node6": "^11.0.0",
11-
"amazon-mws": "^0.0.13",
11+
"amazon-mws": "^0.0.16",
1212
"node-expat": "^2.3.16"
1313
},
1414
"devDependencies": {}

lib/AmazonMwsResource.js

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -151,41 +151,64 @@ AmazonMwsResource.prototype = {
151151
}
152152
}
153153

154-
function processResponseType(res, response, callback) {
154+
function parseCSVFile(res, responseString, delimiter, callback) {
155+
var data = [];
156+
csv.fromString(responseString, {headers: true, delimiter: delimiter, ignoreEmpty: true})
157+
.on('data', function (value) {
158+
data.push(value);
159+
})
160+
.on('end', function () {
161+
debug('response after parsing tab delimited file %o ', data);
162+
var items = {};
163+
items.data = data;
164+
items.Headers = {
165+
'x-mws-quota-max': res.headers['x-mws-quota-max'] || 'unknown',
166+
'x-mws-quota-remaining': res.headers['x-mws-quota-remaining'] || 'unknown',
167+
'x-mws-quota-resetson': res.headers['x-mws-quota-resetson'] || 'unknown',
168+
'x-mws-timestamp': res.headers['x-mws-timestamp']
169+
};
170+
return callback(null, items);
171+
})
172+
.on('error', function (error) {
173+
return callback(error);
174+
});
175+
}
176+
177+
function processResponseType(res, responseString, callback) {
155178
//debug('response %o ', response);
156179
//debug('res.headers %o ', res.headers);
157180
if (RESPONSE_CONTENT_TYPE.indexOf(res.headers['content-type'].toLowerCase()) > -1) {
158181
debug('It is XML Response');
159-
response = xml2json.toJson(response);
182+
var items = xml2json.toJson(responseString);
160183
//debug('response after parsing JSON %o ', response);
161-
response = JSON.parse(response);
162-
response.Headers = {
184+
items = JSON.parse(items);
185+
items.Headers = {
163186
'x-mws-quota-max': res.headers['x-mws-quota-max'] || 'unknown',
164187
'x-mws-quota-remaining': res.headers['x-mws-quota-remaining'] || 'unknown',
165188
'x-mws-quota-resetson': res.headers['x-mws-quota-resetson'] || 'unknown',
166189
'x-mws-timestamp': res.headers['x-mws-timestamp']
167190
};
168191
//debug('after adding header response', response);
169-
return callback(null, response);
192+
return callback(null, items);
170193
} else {
171194
debug('It is NON-XML Response');
172-
var data = [];
173-
csv.fromString(response, {headers: true, delimiter: '\t'})
174-
.on('data', function (value) {
175-
data.push(value);
176-
})
177-
.on('end', function () {
178-
debug('response after parsing tab delimited file %o ', data);
179-
response = {};
180-
response.data = data;
181-
response.Headers = {
182-
'x-mws-quota-max': res.headers['x-mws-quota-max'] || 'unknown',
183-
'x-mws-quota-remaining': res.headers['x-mws-quota-remaining'] || 'unknown',
184-
'x-mws-quota-resetson': res.headers['x-mws-quota-resetson'] || 'unknown',
185-
'x-mws-timestamp': res.headers['x-mws-timestamp']
186-
};
187-
return callback(null, response);
188-
});
195+
var TAB_DELIMITER = '\t';
196+
var COMMA_DELIMITER = ',';
197+
try {
198+
parseCSVFile(res, responseString, TAB_DELIMITER, callback);
199+
} catch (Exception) {
200+
debug('It is TAB_DELIMITER Exception ', Exception);
201+
debug('Let us try to delimit using COMMA_DELIMITER');
202+
try {
203+
parseCSVFile(res, responseString, COMMA_DELIMITER, callback);
204+
} catch (Exception) {
205+
debug('It is COMMA_DELIMITER Exception ', Exception);
206+
debug('Parsing using both TAB_DELIMITER & COMMA_DELIMITER Failed.');
207+
debug('It may due to empty response or invalid request.');
208+
return callback(new Error('Parsing fail.'));
209+
}
210+
}
211+
189212
}
190213
}
191214

lib/amazon-mws.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ var resources = {
3434
sellers: require('./resources/Sellers'),
3535
products: require('./resources/Products'),
3636
orders: require('./resources/Orders'),
37-
reports: require('./resources/Reports')
37+
reports: require('./resources/Reports'),
38+
merchantFulfillment: require('./resources/MerchantFulfillment')
3839
};
3940

4041
AmazonMws.AmazonMwsResource = require('./AmazonMwsResource');
@@ -152,7 +153,7 @@ AmazonMws.prototype = {
152153
cb(AmazonMws.USER_AGENT_SERIALIZED);
153154
});
154155
},
155-
156+
156157
// Gets a JSON version of a User-Agent by encoding a seeded object and
157158
// fetching a uname from the system.
158159
getClientUserAgentSeeded: function (seed, cb) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
var path = require('path');
4+
var AmazonMwsResource = require('../AmazonMwsResource');
5+
var amazonMwsMethod = AmazonMwsResource.method;
6+
7+
module.exports = AmazonMwsResource.extend({
8+
9+
path: 'MerchantFulfillment',
10+
search: amazonMwsMethod({
11+
method: 'GET'
12+
}),
13+
14+
create: amazonMwsMethod({
15+
method: 'GET'
16+
})
17+
18+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "amazon-mws",
3-
"version": "0.0.15",
3+
"version": "0.0.16",
44
"description": "Amazon MWS API wrapper",
55
"keywords": [
66
"Amazon MWS",

0 commit comments

Comments
 (0)