Retrieving assignments on specific questionnaire in the same workspace

I have two questionnaires in the same workspace. There are assignments for both the questionnaires. Is there a way to retrieve assignments of the one questionnaire and exclude the ones for the other questionnaire? I tried using ssaw API but not sure how to go about. Below is my sample script:

from ssaw import Client, AssignmentsApi, QuestionnairesApi
from test_solutions import read_ssolutions_config
import pandas as pd

# ----- Configure the server

test_configs = read_ssolutions_config()

client = Client(test_configs['url'], test_configs['api_user'],
                test_configs['api_password'], workspace="test")


# Get the questionnaires ids

quiz_ids = []

for i in QuestionnairesApi(client, "test").get_list():
    quiz_ids.append(i.questionnaire_id)

quiz_1 = quiz_ids[0]
quiz_2 = quiz_ids[1]

quiz_1_assigns = []
quiz_2_assigns = []


def extract_assignments(quizid, quiz_assignments):
    for i in AssignmentsApi(client).get_list(quizid):
        quiz_assignments.append(i.id)


extract_assignments(quiz_1, quiz_1_assigns)
extract_assignments(quiz_2, quiz_2_assigns)

print(quiz_1_assigns)
print(quiz_2_assigns)

I get the same assignments for all the questionnaires…

Yes, you should be able to retrieve the assignments of just a particular questionnaire if you include a corresponding filter in your graphql API query:

Likewise, using the REST API:

1 Like

And the filters that @sergiy referred are of course implemented and accessible through ssaw client:


AssignmentsApi(client, "test").get_list(questionnaire_id='id of your questionnaire')
1 Like

I had responded too quickly, without seeing what your code was doing …
You do use questionnaire_id filter but there is one more thing missing. Arguably there is a confusion in the naming how these entities are shown in the api endpoints, but for the filter you have to use both questionnaire id (quid value) as well as the version (the concept that is referred as ‘questionnaire identity’ on the api pages).

So you’d simply call the same method with one more parameter:

AssignmentsApi(client).get_list(questionnaire_id='guid', questionnaire_version=version)

Another small comment: if you want to get all the values returned by a generator (for example .get_list() method) you can simply write

questionnaires = list(QuestionnaireApi(client).get_list())

Or if you want to get few values then :

qlist = QuestionnairesApi(...).get_list(...)
first_element = next(qlist)
second_element = next(qlist)
1 Like

Many thanks @sergy for very informative answer. I still have a challenge extracting the assignments for specific questionnaire

Adding the version number solved it. Many thanks

1 Like