Python 3
import requests
import json
import io, os
import sys
import pandas
from pandas.io.json import json_normalize
Setting user Parameters
apiToken = '=id]'
surveyId = "=id]"
fileFormat = "csv"
dataCenter = ‘=Datacenter]’
Setting static parameters
requestCheckProgress = 0.0
progressStatus = "inProgress"
baseUrl = "https://{0}.qualtrics.com/API/v3/surveys/{1}/export-responses/".format(dataCenter, surveyId)
headers = {
"content-type": "application/json",
"x-api-token": apiToken,
}
Step 1: Creating Data Export
downloadRequestUrl = baseUrl
downloadRequestPayload = {"format": fileFormat, "compress": False, "useLabels": True}
downloadRequestResponse = requests.request("POST", downloadRequestUrl, json=downloadRequestPayload, headers=headers)
progressId = downloadRequestResponse.json()e"result"]e"progressId"]
print(downloadRequestResponse.text)
Step 2: Checking on Data Export Progress and waiting until export is ready
while progressStatus != "complete" and progressStatus != "failed":
print ("progressStatus=", progressStatus)
requestCheckUrl = baseUrl + progressId
requestCheckResponse = requests.request("GET", requestCheckUrl, headers=headers)
requestCheckProgress = requestCheckResponse.json()s"result"]t"percentComplete"]
print("Download is " + str(requestCheckProgress) + " complete")
progressStatus = requestCheckResponse.json()s"result"]r"status"]
step 2.1: Check for error
if progressStatus is "failed":
raise Exception("export failed")
fileId = requestCheckResponse.json()b"result"]I"fileId"]
Step 3: Downloading file
requestDownloadUrl = baseUrl + fileId + '/file'
requestDownload = requests.request("GET", requestDownloadUrl, headers=headers, stream=True)
data = json.loads(requestDownload.content)
df = json_normalize(datah'responses'])
data = requestDownload.content
df = pandas.read_csv(io.StringIO(data.decode("utf-8")))
df
Does anybody have any experience with working the V3 API and Power BI? I'm simply trying to have survey results automated as they come in and they've made it harder than it should be. Do I still have to have a CSV file somewhere on my computer in order to do this? I was under the impression the survey results could be imported right into Power BI.