export_responses_by_token
for anonymous surveys
#457
Replies: 3 comments
-
Hi @MatthiasGer0821! It's probably not documented all to well but LimeSurvey only attaches a token (a.k.a. access code) to a response, and creates the >>> client.export_responses(411981, token="sgrw0BtXWbxA6Ws")
---------------------------------------------------------------------------
LimeSurveyApiError Traceback (most recent call last)
<ipython-input-15-15f0803c5896> in <module>
----> 1 client.export_responses(411981, token="sgrw0BtXWbxA6Ws")
~/edgar/citric/src/citric/client.py in export_responses(self, survey_id, token, file_format, language, completion_status, heading_type, response_type, from_response_id, to_response_id, fields)
353 else:
354 return base64.b64decode(
--> 355 self.__session.export_responses_by_token(
356 survey_id,
357 enums.ResponsesExportFormat(file_format),
~/edgar/citric/src/citric/method.py in __call__(self, *params)
42 some_method 1 a
43 """
---> 44 return self.__caller(self.__name, *params)
~/edgar/citric/src/citric/session.py in rpc(self, method, *params)
99 # Methods requiring authentication
100 else:
--> 101 result = self._invoke(self._session, self.url, method, self.key, *params)
102
103 return result
~/edgar/citric/src/citric/session.py in _invoke(session, url, method, *params)
150
151 if error is not None:
--> 152 raise LimeSurveyApiError(error)
153
154 if response_id != request_id:
LimeSurveyApiError: Table "lime_survey_411981" does not have a column named "token". Btw, you can also use citric's |
Beta Was this translation helpful? Give feedback.
-
Hi @edgarrmondragon, thanks for your reply. Yes, the Client.export_responses(, token=...) request from citric works great for the non-anonmyous surveys I have switched. But for the anonymous responses, I think i´m gonna check if by filtering for specific fields (with $aFields) I can check for specific answers. Background of my question is that i´m expecting to have a really large number of anonymous responses and i do not want to receive all of them every time i cal the export_responses function. Best, |
Beta Was this translation helpful? Give feedback.
-
@MatthiasGer0821 Oh I see. So yeah, the only way to get specific responses is to use a range of response IDs, if you already know those IDs. A workaround would be to export all response but only the fields you would like to filter by, store the response ID if a condition is true, and then iterate over response IDs to export all fields only for those responses: import json
import citric
client = citric.Client(...)
sid = 542847
question_code = "Q00"
question_sgq_id = "542847X34X56" # https://manual.limesurvey.org/SGQA_identifier
# Export only the response ID and answers for "Q00"
all_responses = client.export_responses(sid, fields=["id", question_sgq_id])
response_ids = []
for response in json.loads(all_responses)["responses"]:
if response[question_code] == "<SOME VALUE>":
response_ids.append(response["id"])
# Export all fields for a single ID each time
for rid in response_ids:
single_id_resp = client.export_responses(sid, from_response_id=rid, to_response_id=rid)
data = json.loads(single_id_resp)["responses"][0]
print(data) |
Beta Was this translation helpful? Give feedback.
-
Feature Type
Other
Description
Hi @edgarrmondragon,
i might have another use-case where im not sure how to implement it.
I want to export responses for specific tokens in an anonymous survey.
I tried client.session.export_responses_by_token
but i get the error that my survey (which can be called and stuff) does not have the field "token".
Reading the documentation from LS, i am not even sure what token i need to give the function (tokenID? the token to access the survey?)
I was wondering if my problem persists since its an anonymous survey and if you have any thoughts.
Best regards,
Matt
Beta Was this translation helpful? Give feedback.
All reactions