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.