Issue in the downloaded data by API | XM Community
Skip to main content
I was trying to download the survey data by API method using python. I just followed the instructions from https://community.alteryx.com/t5/Alteryx-Designer-Discussions/Python-Tool-Downloading-Qualtrics-Survey-Data-using-Python-API/td-p/304898



I successfully downloaded the unzipped csv file. when I see the data in the csv file and found that the data in the columns got truncated and appeneded with   as below. Please note that the SPANID's are populated well but the questions got truncated as below.



MOD#ABCMOD#CAP#DEFGHIDXXXCAP#PS#YYYNNNMMMPS#DSC#Risk Miti..-     
Have you tried exporting the data by running just the python outside of Alteryx? The code below has worked for me in the past.



```python

#!/usr/bin/env python3

# -*- coding: utf-8 -*-



import zipfile, io



apiToken = '<INSERT YOUR TOKEN HERE>'

dataCenter = '<INSERT DATA CENTER HERE>'

surveyId = '<INSERT SURVEY ID HERE>



# start export file creation

baseUrl = 'https://{0}.qualtrics.com/API/v3/surveys/{1}/export-responses'.format(dataCenter, surveyId)

headers = {

"x-api-token": apiToken,

"Content-Type": "application/json"

}



data = {

"format": "csv",

"startDate": "2019-08-05T16:23:11-06:00", # include these values if you want a date range for the data

"endDate": "2019-08-05T16:23:12-06:00", # include these values if you want a date range for the data

"timeZone": "America/Denver"

}



response = requests.post(baseUrl, json=data, headers=headers)

responseJSON = response.json()

print(response.text)



# get status of export file

progressId = responseJSON['result']['progressId']

baseUrl = 'https://{0}.qualtrics.com/API/v3/surveys/{1}/export-responses/{2}'.format(dataCenter, surveyId, progressId)

headers = {

"x-api-token": apiToken,

"Content-Type": "application/json"

}



response = requests.get(baseUrl, json=data, headers=headers)

responseJSON = response.json()

print(response.text)



# download export file

fileId = responseJSON['result']['fileId']

baseUrl = 'https://{0}.qualtrics.com/API/v3/surveys/{1}/export-responses/{2}/file'.format(dataCenter, surveyId, fileId)

headers = {

"x-api-token": apiToken,

"Content-Type": "application/json"

}



response = requests.get(baseUrl, json=data, headers=headers)

print(response.ok) # check that we got a response

z = zipfile.ZipFile(io.BytesIO(response.content))

test = z.extractall() # you can put a path in here to unzip the file to a certain path

```
Thank you. Yes it works now, afer I changed my API to https://{0}.qualtrics.com/API/v3/surveys/{1}/export-responses/{2}'.format(dataCenter, surveyId, progressId)

Earlier I used the different API that I had mentioned in my post.

Thanks for your help.
Glad it worked! Thanks for giving it a try.

Leave a Reply