Hello kind people,
I'm trying to find a way to download the delta responses by using the continuation option. Below is the cURL that I use. I can run it successfully and get the result if I choose to download it in the "csv" format. However, when I use the below command line, with data format as "json", I get the "httpStatus: 400 - Bad Request" error. I need to have the data in the json file instead of the csv.
Long story short, I can use the command line below to download the csv file but NOT the json file. Could someone help me?
Works: curl --request POST --url https://myCompany.qualtrics.com/API/v3/surveys/mySurveyID/export-responses --header 'content-type: application/json' --header 'x-api-token: myToken' --data '{"format":"csv","useLabels": true,"continuationToken": "myContinuationTokenFromPreviouslyRun"}'
Doesn't work: curl --request POST --url https://myCompany.qualtrics.com/API/v3/surveys/mySurveyID/export-responses --header 'content-type: application/json' --header 'x-api-token: myToken' --data '{"format":"json","useLabels": true,"continuationToken": "myContinuationTokenFromPreviouslyRun"}'
Thank you in advance,
UHutch
useLabels isn't valid with json. From the documentation:
When exporting responses as JSON, not all parameters are meaningful. Consequently, the following parameters are not allowed when starting a JSON or NDJSON export:
includeDisplayOrder useLabels formatDecimalAsComma seenUnansweredRecode multiselectSeenUnansweredRecode timeZone newlineReplacement breakoutSets
Thank you, TomG. I totally missed that.
Here is my code. Before running it, you need to create a text file to store the continuation token. The header can be like "continuationToken|Timestamp". Feel free to update this code for a better run if needed
surveyID='mySurveyID'
token='myToken'
continuationToken=$(echo $(cat My_Text_File_For_Continuation_Token.txt | tail -n1) | awk 'BEGIN{FS="|"} {print $1}')
status=""
percentComplete=""
# 1. Get progressID:
#progressID=$(curl --request POST --url https://myCompany.qualtrics.com/API/v3/surveys/${surveyID}/export-responses --header 'content-type: application/json' --header 'x-api-token: '${token}'' --data '{"format":"json","allowContinuation": true}' | sed -e "s/^.*progressId\\":\\"//" | cut -d'"' -f1) # run this line when downloading the full dataset and get the continuation token for the next incremental run
progressID=$(curl --request POST --url https://myCompany.qualtrics.com/API/v3/surveys/${surveyID}/export-responses --header 'content-type: application/json' --header 'x-api-token: '${token}'' --data '{"format":"json","continuationToken":"'${continuationToken}'"}' | sed -e "s/^.*progressId\\":\\"//" | cut -d'"' -f1)
echo "progressID = ${progressID}"
while [[ ${status} != "complete" && ${status} != "failed" ]] ; do
status=$(curl --request GET --url https://myCompany.qualtrics.com/API/v3/surveys/${surveyID}/export-responses/$progressID --header 'x-api-token: '${token}'' | sed -e "s/^.*status\\":\\"//" | cut -d'"' -f1)
percentComplete=$(curl --request GET --url https://myCompany.qualtrics.com/API/v3/surveys/${surveyID}/export-responses/$progressID --header 'x-api-token: '${token}'' | sed -e "s/^.*percentComplete\\"://" | cut -d'"' -f1)
echo ${status}: ${percentComplete}
done
fileID=$(curl --request GET --url https://myCompany.qualtrics.com/API/v3/surveys/${surveyID}/export-responses/$progressID --header 'x-api-token: '${token}'' | sed -e "s/^.*fileId\\":\\"//" | cut -d'"' -f1)
echo "fileID = ${fileID}"
continuationToken=$(curl --request GET --url https://myCompany.qualtrics.com/API/v3/surveys/${surveyID}/export-responses/$progressID --header 'x-api-token: '${token}'' | sed -e "s/^.*continuationToken\\":\\"//" | cut -d'"' -f1)
echo "continuationToken = ${continuationToken}"
# append the continuation token to an existing text file
echo ${continuationToken}'|'`date +"%Y%m%d_%H%M%S"` >> My_Text_File_For_Continuation_Token.txt
# 3. Get Zip file:
curl --request GET --url https://myCompany.qualtrics.com/API/v3/surveys/${surveyID}/export-responses/${fileID}/file --header 'x-api-token: '${token}'' --output temp.zip
# 4. Unzip temp.zip file:
unzip temp.zip
# at this point, you get the JSON file
UHutch
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.