Using the API for random assignment of a survey | XM Community

Using the API for random assignment of a survey

  • 22 November 2022
  • 2 replies
  • 25 views

Badge +1

Hello everyone
I have been looking for the answer to this question but have yet to be lucky.
Some context: I have a group of images (2000) that I want to be rated by participants in a study on their emotional content. I have created the JSON with all the survey elements (images and text) and structure (first, introduction, then question 1, and so on).
The problem is that not every image should be rated by each participant. I want to distribute them randomly for each participant at 100 per participant. This is where I would like the Qualtrics API to jump in.
How can I give the API my JSON files —namely, 20 different surveys with 100 images each— and make it choose one (and just one) to assign to each participant in equal proportions across participants?
Have a lovely day!


2 replies

Userlevel 5
Badge +25

Hi David_UB,
If you're sending 20 different surveys, you will need 20 different distributions. Rather than randomly selecting a survey to send to a participant, you'll have an easier time randomly assigning participants to a distribution list, and then sending out each one.
This endpoint allows you to create a mailing list.
This endpoint creates a contact in a mailing list.
And this endpoint allows you to distribute a given survey for a specified mailing list.
So if I were you, I'd try to write a script that performs the following:

  • Create 20 mailing lists (first endpoint), store the IDs of each

  • Pair each mailing list with a survey ID

  • Randomly iterate through each mailing list ID, creating a contact for one participant (second endpoint). Repeat until no more participants remain.

  • Iterate through each mailing list ID, sending out a distribution (third endpoint) for the paired survey ID in step 2.

As far as random selection goes, Python has a built in sampling function which performs selection without replacement.
Good luck!

Userlevel 7
Badge +21

You don't need the API for this.
Create 20 blocks with 100 images each and then use a randomizer to show one block.

Leave a Reply