t3chnoboy / amazon-product-api

:credit_card: Amazon Product Advertising API client
365 stars 104 forks source link

API return LowestNewPrice instead of Price #68

Open s1lviu opened 7 years ago

s1lviu commented 7 years ago

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

masterT commented 7 years ago

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

maenthoven commented 7 years ago

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)
masterT commented 7 years ago

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 commented 7 years ago

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

t3chnoboy commented 7 years ago

Yeah, looks like one more breaking change 😕

t3chnoboy commented 7 years ago

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

masterT commented 7 years ago

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

FdezRomero commented 7 years ago

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.

s1lviu commented 7 years ago

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

masterT commented 7 years ago

No problem!

raugaral commented 6 years ago

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!