Hello,
After playing around for a few days I got the below code working now. I want to use API to download responses. This is done in three steps. The only thing I can't get working now is: where do I find the file containing the csv data. Or how can I export and download it to my local harddrive? What changes do I need to make to the code: (the API-token is not my real token and the surveyID is not my real SurveyID)
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var apikey = "mYaPiKeYfOrQuAlTrIcS0123";
var sId = "SV_8vrnABcdeFGH06i"
//Step 1
var data = JSON.stringify({
"format": "csv",
"compress": false,
"exportResponsesInProgress": false
});
var xhr1 = new XMLHttpRequest();
xhr1.withCredentials = true;
xhr1.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
var rs = JSON.parse(this.responseText);
var pId = rs.result.progressId;
var URL2 = "https://fra1.qualtrics.com/API/v3/surveys/"+sId+"/export-responses/"+pId;
Qualtrics.SurveyEngine.setEmbeddedData("progressId", rs.result.progressId);
//Step 2
var data = null;
var xhr2 = new XMLHttpRequest();
xhr2.withCredentials = true;
xhr2.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
var rs2 = JSON.parse(this.responseText);
var fId = rs2.result.fileId;
Qualtrics.SurveyEngine.setEmbeddedData("fileId", rs2.result.fileId);
//Step 3
var data = null;
var URL3 = "https://fra1.qualtrics.com/API/v3/surveys/"+sId+"/export-responses/"+fId+"/file";
var xhr3 = new XMLHttpRequest();
xhr3.withCredentials = true;
xhr3.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
var file = this.responseText;
}
Qualtrics.SurveyEngine.setEmbeddedData("URL3", URL3);
Qualtrics.SurveyEngine.setEmbeddedData("file", file);
});
//request for step 3
xhr3.open("GET", URL3);
xhr3.setRequestHeader("x-api-token", apikey);
xhr3.send(data);
//
}
});
// request for step 2
xhr2.open("GET", URL2);
xhr2.setRequestHeader("x-api-token", apikey);
xhr2.send(data);
}
});
//request for step 1
xhr1.open("POST", "https://fra1.qualtrics.com/API/v3/surveys/"+sId+"/export-responses");
xhr1.setRequestHeader("x-api-token", apikey);
xhr1.setRequestHeader("content-type", "application/json");
xhr1.send(data);
});
Many thanks in advance.
Kind regards, Nico
How to store data into a downloadable csv-file?
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
