amazon-product-api icon indicating copy to clipboard operation
amazon-product-api copied to clipboard

API return LowestNewPrice instead of Price

Open s1lviu opened this issue 8 years ago • 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

s1lviu avatar Nov 18 '16 20:11 s1lviu

Sorry for the long delay, but I don't really understand the problem, can you formulate?

masterT avatar Jan 27 '17 16:01 masterT

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)

maenthoven avatar Feb 05 '17 04:02 maenthoven

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.

masterT avatar Feb 05 '17 12:02 masterT

@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.

masterT avatar Feb 05 '17 12:02 masterT

Yeah, looks like one more breaking change 😕

t3chnoboy avatar Feb 05 '17 12:02 t3chnoboy

seems like it's related to https://github.com/t3chnoboy/amazon-product-api/pull/62 https://github.com/t3chnoboy/amazon-product-api/issues/63

t3chnoboy avatar Feb 05 '17 13:02 t3chnoboy

Yes. I think we should let the consumer have the full control over his requests.

masterT avatar Feb 05 '17 13:02 masterT

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.

FdezRomero avatar Feb 05 '17 13:02 FdezRomero

Sorry, @masterT. I've exited long time ago from that project.

s1lviu avatar Feb 13 '17 16:02 s1lviu

No problem!

masterT avatar Feb 13 '17 16:02 masterT

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!

raugaral avatar Nov 30 '17 12:11 raugaral

This is still not resolved - people are going to download this and be banging their heads over why the price returned is not the amazon main price like EVERY other amazon api client out there does.

elliotthill avatar Jan 17 '18 15:01 elliotthill