How to create a block with questions using Qualtrics API | XM Community
Question

How to create a block with questions using Qualtrics API

  • 8 March 2024
  • 0 replies
  • 28 views

Badge +1

Hi all, I’m trying to create a block from the qualtrics API with Python following the API documentation: https://api.qualtrics.com/2d5286cc34ed6-create-block. Running the example code snippets do not work for me.

 

If I try to run the small example code that they have provided, I seem to get a 'Invalid request. Missing or invalid parameter ID.' error

```

import requests
 
data_center_id = "fra1"
survey_id = "<Your Survey ID>"
url = f"https://{data_center_id}.qualtrics.com/API/v3/survey-definitions/{survey_id}/blocks"
api_token = "<Your API Token>"
 
payload = {
  "Type": "Standard",
  "Description": "My Block Name",
  "ID": "BL_fakeblockid1234",
  "BlockElements": [
    {
      "Type": "Question",
      "QuestionID": "QID1"
    }
  ],
  "Options": {
    "BlockLocking": "false",
    "RandomizeQuestions": "false",
    "BlockVisibility": "Collapsed"
  }
}
headers = {
  "Content-Type": "application/json",
  "Accept": "application/json",
  "X-API-TOKEN": api_token
}
 
response = requests.post(url, json=payload, headers=headers)
 
response.json()
```
 
I have tried removing the “ID” field from the payload, and in that case I will get a ‘Invalid request. Missing or invalid parameter BlockElements.’ error. Even using the code panel provided on the right on the documentation page (https://api.qualtrics.com/2d5286cc34ed6-create-block) where you fill in the API token and Survey ID, it will fail.
 
For completeness, this is the full response I get when removing the “ID” field:
 
{'meta': {'requestId': '5412267a-981c-4abb-b532-d2a4a16c7307', 'httpStatus': '400 - Bad Request', 'error': {'errorCode': 'QMST_1', 'errorMessage': 'The request was invalid.', 'code': 'ESRV35', 'message': 'Invalid request. Missing or invalid parameter BlockElements.'}}}
 
I am able to create an empty block if I remove “ID” and “BlockElements” though.
 
Any help will be much appreciated!
 

0 replies

Be the first to reply!

Leave a Reply