Is there any way to add or edit subquestion and answer options? #1131
-
|
I was working quite well with Citric, I managed to create surveys, groups, and import questions, but I hit a wall in my development when I realized that the API doesn't incorporate a method that allows me to edit subquestions and answer options. Is this a limitation of the API or of Citric? Is there anything I can contribute to resolve this limitation? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
|
Hi @microplasticos! Thanks for the feedback. Maybe #971 (comment) is helpful, have you seen tried something like that? |
Beta Was this translation helpful? Give feedback.
-
|
Hello there! 👋 I just v2.0.0 of the library, which includes a new method to update answer options in a question. Here's a quick example: from citric.rest import RESTClient
client = RESTClient(
"https://example.com/rest/v1",
"your_username",
"your_password",
)
survey_id = 142423
# Get survey details
survey = client.get_survey(survey_id)
print(survey)
# Inspect question 247 to find answer IDs
for question in survey["questionGroups"][0]["questions"]:
if answers := question.get("answers"):
print("Answers for question", question["qid"])
for answer in answers:
print(f" Answer ID: {answer['aid']}, Code: {answer['code']}")
# Define patch operations
operations = [
{
"entity": "answer",
"op": "update",
# Question ID
"id": 247,
"props": [
{
# Answer ID
"aid": 31,
"code": "AO01",
"sortOrder": 1,
"assessmentValue": 0,
"scaleId": 1,
"l10ns": {
"de": {"answer": "ANTW1 scale 1", "language": "de"},
"en": {"answer": "ANS1 scale 1", "language": "en"},
},
},
{
# Answer ID
"aid": 32,
"code": "AO02",
"sortOrder": 1,
"assessmentValue": 0,
"scaleId": 1,
"l10ns": {
"de": {"answer": "ANTW2 scale 1", "language": "de"},
"en": {"answer": "ANS2 scale 1", "language": "en"},
},
},
{
# Answer ID
"aid": 33,
"code": "AO03",
"sortOrder": 1,
"assessmentValue": 0,
"scaleId": 1,
"l10ns": {
"de": {"answer": "ANTW3 scale 1", "language": "de"},
"en": {"answer": "ANS3 scale 1", "language": "en"},
},
},
],
}
]
result = client.patch_survey(survey_id, operations)
print(f"Operations applied: {result['operationsApplied']}") # Operations applied: 1It's also available in the docs. I would love to hear your feedback! N.B. I'd like to add a more high-level API for this, but the LimeSurvey REST API seems to still be in-flux, so I'm waiting for it to stabilize before doing so. |
Beta Was this translation helpful? Give feedback.
A pity indeed! I submitted a feature request, let's see what the maintainers think: https://bugs.limesurvey.org/view.php?id=19574