Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Qualtrics API/Python Script

I've been trying for the longest to figure out how to import survey results from Qualtrics into Power BI using Python. Qualtrics support has given me code and I was told all I needed to do was change the apiToken, surveyId, fileFormat and dataCenter lines below but I have not been able to get this to work:


# 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()["result"]["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()["result"]["percentComplete"]

    print("Download is " + str(requestCheckProgress) + " complete")

    progressStatus = requestCheckResponse.json()["result"]["status"]

 

#step 2.1: Check for error

if progressStatus is "failed":

    raise Exception("export failed")

 

fileId = requestCheckResponse.json()["result"]["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(data['responses'])

data = requestDownload.content

df = pandas.read_csv(io.StringIO(data.decode("utf-8")))

df

 

I'm not a developer nor do I have Python experience, so I have no clue what I would need to change to get what I'm looking for. I'm slightly confused because this seems to be code for exporting results to a CSV, but I was hoping to connect straight from Power BI to Qualtrics. 

0 REPLIES 0

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.