I'm really confused about why I can not return the JSON result from amazonMws.products.search()
and could use some help understanding what is going on. When I write it this way gives me undefined
:
function listMatchingProducts(query) {
const options = {
Version: VERSION,
Action: 'ListMatchingProducts',
MarketplaceId: MARKET_PLACE_ID,
SellerId: SELLER_ID,
Query: query
}
amazonMws.products.search(options, (err, res) => {
if(err){
throw(err)
return
}
return res
})
}
I also get undefined
when using amazonMws.products.search().then().catch()
as well.
If I return amazonMws.products.search()
I get a promise back instead of the result.
Inside of the callbacks if I console.log(res)
I get back the JSON result I'm expecting. So this led me to believe I need to use async await
I think, but this results in Promise { <pending> }
:
async function listMatchingProducts(query) {
const options = {
Version: VERSION,
Action: 'ListMatchingProducts',
MarketplaceId: MARKET_PLACE_ID,
SellerId: SELLER_ID,
Query: query
}
return await amazonMws.products.search(options)
.then(res => {
return res
})
.catch(e => errorHandler(e))
}
I am totally lost, so if someone could explain to me what is going on, that would be greatly appreciated.