For my school project, I am working on an e-commerce aggregator site where I need to combine product data from 3 different APIs (like Aliexpress and Amazon) into one homepage. Although I can retrieve results from each API individually, I'm facing challenges in storing these results in a collated_results_list. Whenever I try to append or return the individual_results to the collated_results_list, it either shows undefined or doesn't add the individual_results at all.
The project is mainly focused on Javascript and AJAX, but I can also incorporate other libraries as long as they don't replicate the functionalities of JS and AJAX. Any assistance in resolving this issue would be highly appreciated. Thank you!
The following pseudocode represents the general structure of my script:
//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;
//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;
}