I am doing a e-commerce aggregator site for an school project and I am looking to collate products from 3 separate APIs that would retrieve data from e-commerce sites such as Aliexpress or Amazon before placing it into 1 homepage.
Currently, I am able to retrieve the results from each individual APIs but am unable to store the results into a collated_results_list. When I try to return or append the individual_results to the collated_results_list, it returns undefined or does not append any individual_results to the collated_results_list.
My school project is based on Javascript and AJAX but is also able to use other libraries as long as they do not perform the same function as JS and AJAX. Would really appreciate it if anyone could help me out. Thank you!
The following code block is the pseudocode for my script in general.
//Inside populate_search_result_page.js
function collate_results(){
var collated_results_list = [];
var amazon_list = call_amazon_api(); // returns undefined
var aliexpress_list = call_aliexpress_api(); // returns undefined
var taobao_list = call_taobao_api(); // returns taobao_list = undefined;
// Expected output: taobao_list = taobao_product_list;
//collate all results from all APIs
collated_results_list.concat(amazon_list, aliexpress_list, taobao_list );
for loop (collated_results_list) {
Using collated_results_list, populate search result page in a sorted manner;
}
}
function call_amazon_api(){
return amazon_product_list; //results can be printed within call_amazon_api, but cannot be passed to
//another global variable
}
function call_aliexpress_api(){
return aliexpress_product_list;
}
function call_taobao_api(){
return taobao_product_list;
}