I am currently working with an array of projects and an array of dates. My goal is to map the dates to the projects and make API calls to retrieve report URLs. I am trying to collect an array of objects that contain the URLs and the corresponding name-date of the projects, if the data exists and I receive the URL. However, my current code is only returning an array of objects with promises...
const getURL = async url => {
try {
await fetch(url, {method: 'GET', headers: headers_data})
.then(response => response.json())
.then(data => data.urls[0]);
} catch (error) {
console.log('Error getting links', error);
}
};
let linksToDownload = [];
await Promise.all(dateOfReport.map(async (date) => {
await Promise.all(apps.map(async (appId) => {
const API = process.env.API + appId + "&date=" + date ;
let url = getURL(API)
let obj = {
name: date + "appId" + appId,
value: url,
}
return linksToDownload.push(obj);
}));
return;
}));
console.log(linksToDownload);
Currently, my log displays:
[
{ name: '2020-04-29appIdda555', value: Promise { <pending> } },
{ name: '2020-04-29appIdqqq444', value: Promise { <pending> } },
{ name: '2020-04-30appIdda555', value: Promise { <pending> } },
{ name: '2020-04-30appIdqqq444', value: Promise { <pending> } }
]
I appreciate any help in resolving this issue. Thank you.