Connecting Qualtrics to PowerBi | XM Community
Question

Connecting Qualtrics to PowerBi

  • 6 April 2022
  • 4 replies
  • 713 views

Badge

Hi Guys,
I am trying to export responses from Qualtrics to PowerBI. I am totally new to this API concept. I downloaded some code from Github and put together the below code. Unfortunately the python code not working and I see there is some issue with the URL. Can you please help / advise.
import requests
import zipfile
import io
import os
def get_qualtrics_survey(dir_save_survey, survey_id):
 
    # user Parameters
    api_token = "XXXX"
    file_format = "csv"
    survey_id = "SV_2gwpQ5QDawpuFEO"
    data_center = "XXXX"

    # static parameters
    request_check_progress = 0
    progress_status = "in progress"
    #base_url = "https://iad1.qualtrics.com/API/V3/surveys/SV_2gwpQ5QDawpuFEO/export-responses/".format(data_center)
    base_url = "https://iad1.qualtrics.com/API/v3/survey_id/export-responses"
    headers = {
        "content-type": "application/json",
        "x-api-token": api_token,
    }

    # Data Export
    download_request_url = base_url
    download_request_payload = '{"format":"' + file_format + '","surveyId":"' + survey_id + '"}' # you can set useLabels:True to get responses in text format
    download_request_response = requests.request("POST", download_request_url, data=download_request_payload, headers=headers)
    progress_id = download_request_response.json()["result"]["id"]
    # print(download_request_response.text)

    # Checking on Data Export Progress and waiting until export is ready
    while request_check_progress < 100 and progress_status != "complete":
        request_check_url = base_url + progress_id
        request_check_response = requests.request("GET", request_check_url, headers=headers)
        request_check_progress = request_check_response.json()["result"]["percentComplete"]

    # Step 3: Downloading file
    request_download_url = base_url + progress_id + '/file'
    request_download = requests.request("GET", request_download_url, headers=headers, stream=True)

    # Step 4: Unzipping the file
    zipfile.ZipFile(io.BytesIO(request_download.content)).extractall(dir_save_survey)
    print('Downloaded qualtrics survey')
    path = "c:/Users/juliafx1/OneDrive - Abbott/Python/"
    get_qualtrics_survey(dir_save_survey = path, survey_id = survey_id)


4 replies

Badge +1

There are a few edits I would make. First off if that's your actual API key and data center ID I would remove it from this post, otherwise anyone can use that and pull your data.
As for edits, my data center is just four characters, I don't think you need the "y"s that are representative of the data center ID you have listed. Just use the "x" portion. e.g( "yyyyy.xxxx")
Update your URL to this format:
base_url = "https://{0}.qualtrics.com/API/v3/surveys/{1}/export-responses/".format(data_center, survey_id)
Off the bat, those are the only comments I have. Let me know if you're still having trouble and if there are any specific error messages.

Badge

Hi,
I understand {0} is just the Data center id and {1} is the survey id correct ? If that's the case its still not working. Please advise.


Badge

{0} replaces data center id & {1} replaces survey_id correct ?

Badge +2

https://community.qualtrics.com/XMcommunity/discussion/comment/45330#Comment_45330Hi again, Fabian. Yes, that's right. Those are string format funcitons. Anything inside the curly brackets is replaced by the positional arguments in the .format() method. The numbers or names inside the brackets are arbitrary. Another version is f-string formatting, like this :
f"https://{data_center}.qualtrics.com/API/v3/surveys/{survey_id}/export-responses/"
Each style has its trade-offs.

Leave a Reply