Hi everyone,
I am trying to call an API to fetch some data. but there is another related data which is available at the different endpoint of the API. so basically I have to first call first API and take one attribute from the response then call another API based on that attribute.
I have written a JavaScript Query for that, and its showing the correct results in the console but it's returning the data. following is the query code. please help.
var final = [];
fetch("https://api.calendly.com/scheduled_events?user=https%3A%2F%2Fapi.calendly.com%2Fusers%2FFDCFEKEOCOBGYQ5B&status=active", {
"method": "GET",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer token_here"
}
})
.then(response => response.json())
.then(data_events => {
for(var i in data_events.collection)
{
fetch(data_events.collection[i].uri + "/invitees?status=active", {
"method": "GET",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer token_here"
}
})
.then(response => response.json())
.then(data => {
final[i] = {name: data.collection[0].name, email: data.collection[0].email, created_at: data_events.collection[i].created_at, start_time: data_events.collection[i].start_time, end_time: data_events.collection[i].end_time, status: data_events.collection[i].status}
})
.catch(err => {
console.error(err);
});
}
return final;
})
.catch(err => {
console.error(err);
});