API return LowestNewPrice instead of Price
Opened this issue · 11 comments
client.itemSearch({
responseGroup: 'Images,ItemAttributes,OfferFull',
keywords: 'potatoes'
}, function (err, results, response) {
if (err) {
console.log(err);
} else {
for (var i in results) {
if (results.hasOwnProperty(i)) {
console.log(results[i].Offers[0].Offer[0].OfferListing[0].Price[0].FormattedPrice[0]);
}
}
}
});
I’m trying to get the product current price, but with the following code I receive always the LowestNewPrice. I don’t understand because are different objects.
Here is a example of output.
In scratchpad I receive the expected result and more than this, I get succesfully the other elements like price or images, but for price it’s not working.
Regards,
Silviu
Sorry for the long delay, but I don't really understand the problem, can you formulate?
I can. Your prices are often incorrect.
We've switched to using 'apac' library, found here: https://github.com/dmcquay/node-apac
Compare these two code snippets
Using amazon-product-api
amazon = require('amazon-product-api'),
client = amazon.createClient({
awsId: "xxxxxxxxxxxxxxxxx",
awsSecret: "xxxxxxxxxxxxxxxxx",
awsTag: "xxxxxxxxxxxxxxxxx"
});
function lookup (asin) {
return client.itemLookup({
ItemId: asin,
ResponseGroup: "Offers"
}).then(data => data[0].Offers[0].Offer[0].OfferListing[0].Price[0].Amount[0]);
//NOTE: No where in "data" does 4888 exist
}
lookup("B01GWLIYUI").then(price => console.log(price));
//Prints 4318, WRONG PRICE
Using apac
const {OperationHelper} = require("apac");
const bluebird = require("bluebird");
var parseString = require("xml2js").parseString;
var parse = bluebird.promisify(parseString);
const opHelper = new OperationHelper({
awsId: "xxxxxxxxxxxxxxx",
awsSecret: "xxxxxxxxxxxxxxx",
assocId: "xxxxxxxxxxxxxxx"
});
function getAmazonPriceData (asin) {
return opHelper.execute("ItemLookup", {
"ItemId": asin,
"ResponseGroup": "Offers"
})
.then(response => parse(response.responseBody))
.then(parsed => parsed.ItemLookupResponse.Items[0].Item[0].Offers[0].Offer[0].OfferListing[0].Price[0].Amount[0]);
}
getAmazonPriceData("B01GWLIYUI").then(price => console.log(price));
//Outputs 4888 (Correct Value)
I tested it and this is the XML responses.
As you can see the amazon-product-api
has more params in the request than the apac
request. This is because this module sets some request params by default.
https://github.com/t3chnoboy/amazon-product-api/blob/master/lib/utils.js#L53
When I commented the default params assignation, I got the exact same price amount:
apac: 4368
amazon-product-api: 4368
I included in the previous gist the response with no default params.
@t3chnoboy I think we should remove the default params assignation? I make the module less flexible - you can't make simple request, such as the one above.
Yeah, looks like one more breaking change 😕
Yes. I think we should let the consumer have the full control over his requests.
I agree. Devs expect to get the buy box / main price, which they don't without overriding the default parameters. So it makes perfect sense for 1.0.
No problem!
That is not resolved!
The response no return the amazon price, only the 3th part offers...
To test: do a search by sony in the amazon scratchpad (http://webservices.amazon.es/scratchpad/index.html) and compare the result with the response data from this library .... It's not the same!