Ribhnux / piranhax

Complete implementation package of Amazon Product Advertising API for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Excellent project but CartModify does not work

opened this issue · comments

(node version: v8.9.1, location: US)
The following is the code I tried:

app.post('/test', function(req, res) {
client.ItemSearch("Books", {
Keywords: "Calculus",
ResponseGroup: ["Large"]
}).then(results => {
let Item = results.get("Item")
let OfferListingIds = _.map(Item, i =>
_.get(i, "Offers.Offer.OfferListing.OfferListingId"))
.filter(i => i !== undefined)

  // map OfferListingId
  let AddToCartItems = _.map(OfferListingIds, id => {
      let item = client.CreateCartItem("OfferListingId", id, 1)
      return item
  })

  // create request
  return client.CartCreate(AddToCartItems)
}).then(result => {
  // get CartId
  let CartId = result.get("CartId")

  // get HMAC and one of CartItemId
  let HMAC = result.get("HMAC")
  //let CartItemId = result.get("CartItems.CartItem[0].CartItemId")

  let CartItem = client.CreateCartItem("CartItemId",
    result.get("CartItems.CartItem[0].CartItemId"), 3)

  // do CartModify operation
  return client.CartModify([CartItem], CartId, HMAC)

}).then(result => {
  res.json(result.data());
}).catch(err => {
    console.log(err)
})

})

Error: Response is invalid.
URL: http://webservices.amazon.com/onca/xml?AWSAccessKeyId="removed"&
AssociateTag="removed"&CartId=145-0858664-6963637&HMAC=NTfA%2BZqYdeZsUZVZ
GCUbS0IOgwc%3D&Item.0.CartItemId=C1CGA357CPH4DG&Item.0.Quantity=3&Operation=Cart
Modify&Service=AWSECommerceService&Timestamp=2017-12-20T19%3A09%3A24.854Z&Versio
n=2013-08-01&Signature=1BWBQgwMdvm5UPf7dB%2F9DW6yHGt3fMPE1cb0zzxpIxU%3D
at parseString (..\node_modules\piranhax\lib\request.js:229:33)
at Parser. (..\node_modules\xml2js\lib\parser.js:303:18)
at emitOne (events.js:116:13)
at Parser.emit (events.js:211:7)
at SAXParser.onclosetag (..\node_modules\xml2js\lib\parser.js:261:26)
at emit (..\node_modules\sax\lib\sax.js:624:35)
at emitNode (..\node_modules\sax\lib\sax.js:629:5)
at closeTag (..\node_modules\sax\lib\sax.js:889:7)
at SAXParser.write (..\node_modules\sax\lib\sax.js:1436:13)
at Parser.exports.Parser.Parser.parseString (..\node_modules\xml2js\lib\parser.js:322:31)
at Parser.parseString (..\node_modules\xml2js\lib\parser.js:5:59)
at exports.parseString (..\node_modules\xml2js\lib\parser.js:354:19)
at Request.request [as _callback] (..\node_modules\piranhax\lib\request.js:216:17)
at Request.self.callback (..\node_modules\request\request.js:186:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)

Hi, thank you for posting your issue here. I'll investigate the problem you encounter.

The issue arose from my account limitation.

OK. Thank you for confirming it.