Issue in the downloaded data by API | XM Community
Skip to main content
Solved

Issue in the downloaded data by API

  • October 15, 2019
  • 3 replies
  • 234 views

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..-     

Best answer by KeirJ

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 ```
View original

KeirJ
QPN Level 2 ●●
Forum|alt.badge.img+7
  • QPN Level 2 ●●
  • October 16, 2019
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 ```

  • October 17, 2019
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.

KeirJ
QPN Level 2 ●●
Forum|alt.badge.img+7
  • QPN Level 2 ●●
  • October 17, 2019
Glad it worked! Thanks for giving it a try.

Leave a Reply