Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
Use returned object outside of an async function

I have the following function that gets a survey from Qualtrics:

const fetchQualtricsSurvey = async () => {
    const token = await getAccessToken();
    const progress = await startResponseExport(token);
    const fileId = await getResponseExportProgress(token, progress);
    const survey = await getResponseExportFile(token, fileId);
    console.log(survey);
};

fetchQualtricsSurvey();

It's currently logging the survey to the console. However, I want to use the JSON that I get in other parts (e.g., visualizing the data using other libraries).

Everytime I try to create a global variable that holds survey I get a promise pending.

Here is the getResponseExportFile function for reference:

async function getResponseExportFile(accessToken, fileId) {
    try {
        const res = await axios(
            `${baseUrl}/API/v3/surveys/${surveyId}/export-responses/${fileId}/file`,
            {
                headers: {
                    Authorization: `Bearer ${accessToken}`
                }
            }
        );
        return res.data.responses;
    } catch (err) {
        console.log(err);
    }
}

How on earth do I use survey outside of this whole async function? Is it even possible? I need to access properties of survey object and use them as values somewhere else.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!