Calling API from JavaScript Not Returning Results

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);
});

Hi @samran :wave:

Happy to help you out here with your query. When you say you're seeing the results in the console but not the data, may you confirm that for me please? Take a look in the left hand inspector and find your query. Run it and check out it's data property. What do you see? May you send over a screenshot of this query as well, please? Thank you!

Best

Pawan

Hi @Pawan ,

thanks for looking into the issue I posted. I have waited long, and at the end I figured it out two days ago. :smiley:

thanks again,
Samran

@Pawan I'm going to piggy back here, I'm having the same issue but not finding what I have done incorrectly.

Hey @daviddcarmona! Stepping in for Pawan here. Would you mind sharing a screenshot of query11 itself? Thank you!

@victoria I was able to make this work it was how I was return or I should say not returning the data.

That’s great! Glad it’s working for you and thank you for following up :blush:

Hi,
Can you please guide how to get the data on my output window. I am facing a similar problem. I ran my code with GET request in javascript query block. The json results can be seen in the console, but not as an output.
My end goal is to populate this result jsons into a table.
Thanks in advance!

Hey @dhivya.s! Happy to help here :slight_smile:

Would you mind sharing a screenshot of your current GET request?

https://docs.retool.com/queries/guides/api-requests