Get survey questions and answer options using RPC

More
3 years 5 months ago #131957 by frederikprijck
Hi guys,

I'm looking for a way to get the all the questions with their corresponsing answers for a specific survey using the RPC api.

Remark: I'm not looking for filled-in entries or survey results. However I am interested in an overview of all the possible questions and their answers for that specific survey.

Anyone around here who can guide me to the correct RPC method(s) ?
Currently I can get all the questions using list_questions method supplying both the SessionKey and SurveyId.
This response, however, does not include the possible answers.

Please also note that I would like to limit the amount of RPC calls.

Please Log in or Create an account to join the conversation.

LimeSurvey Partners
More
3 years 5 months ago - 3 years 5 months ago #131969 by frederikprijck
One more addition: We would love to get the question and the answers in all available languages.

However, it's acceptable to seperate this in n+1 calls, where n is the amount of languages used (preferably I would love this in 1 call, but there's no issue if this won't be possible in a single call).

- 1 call to get all the languages for the survey
- 1 call for each language to get the questions / answers.
Last edit: 3 years 5 months ago by frederikprijck.

Please Log in or Create an account to join the conversation.

More
3 years 5 months ago #131975 by Mazi
This is actually a pretty complex scenario because there can be more than one data set for a single question, example:
- list radio question type = 1 column at the response table
- multiple choice / array questions = 1 column for each sub-question = X columns
- Array texts/numeric = 1 column for each cell = X*Y columns for each sub-questions/answer option combination

That makes querying responses + answers (+ maybe sub-question details) pretty complex.

Since you also mention using multiple languages a solution can be to code your own function to retrieve data + labels for each question type and pass it the language short code in order to get the labels in a certain language.

Not that easy to implement...

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com
Want to use your survey offline -> www.offlinesurveys.com

Please Log in or Create an account to join the conversation.

More
3 years 5 months ago - 3 years 5 months ago #131984 by frederikprijck
Dear,

Thanks in advance. Sad to hear this can't be done with a few simple calls. For me it sounds like the basics of a survey application: export it's surveys, with it's questions and answers.
This way I could create a survey using my favorite JS framework for the frontend development instead of creating a LS theme which I can not control 100%.

Let's say I am no longer interested in the question's answers, I should be able to help myself with the list_questions RPC method right ?

I'm having an issue with this RPC method.
This method has 4 parameters
  • sSessionKey: required
  • iSurveyID: required
  • iGroupID: optional
  • sLanguage: optional

I now have different scenario's how I call this method:
  • Only supply sSessionKey and iSurveyID: I get the expected result: all questions for all groups in the default language ('fr' in my case).
  • Supply sSessionKey, iSurveyID and sLanguage='fr': I get the following exception: CDbCommand failed to execute the SQL statement: SQLSTATE[22018]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Conversion failed when converting the nvarchar value 'fr' to data type int.
    Wow, why is it trying to cast the 'fr' part to an int ?
  • Supply sSessionKey, iSurveyID and iGroupID=24: I get the expected result: all question for group 24 in the default language ('fr' in my case)
  • Supply sSessionKey, iSurveyID sLanguage='fr' and iGroupID=24: I get the "status": "Error: Invalid language"
    Wow, why is 'fr' an invalid language ?

So whenever sLanguage is involved in the call, there's an issue.
I've digged abit into the source code, but I'm not a PHP developer so sadly I didn't manage to debug it.
Apart from the above issues, I'm wondering whether 'fr' (= language short code) is to be used ? It is the exact same value as the language column in the lime_questions table.
Last edit: 3 years 5 months ago by frederikprijck.

Please Log in or Create an account to join the conversation.

More
3 years 5 months ago #131988 by DenisChenu

frederikprijck wrote: ....
]Supply sSessionKey, iSurveyID sLanguage='fr' and iGroupID=24: I get the "status": "Error: Invalid language"
Wow, why is 'fr' an invalid language ?
....

Seems it's a bug in RC : it search language in "restricted language" and not in survey language.

Quick workaround : add french to your global restricted language
Fix : make a bug report

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand .
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

More
3 years 5 months ago - 3 years 5 months ago #131989 by frederikprijck
The above problems have been resolved thanks to sammusa !

What was the issue:
My parameters where sent in the incorrect order so the language was parsed as the groupID and vica verca.

This sounds like a pretty simple issue, but I've never had issues like this before. I guess it has something to do with the first time calling an RPC from .NET => PHP.

For the other part of the question I'm going to have a look at packagist.org/packages/sam-it/ls2-jsonrpc-client
If possible, I'll try to create a .NET package for the RPC methods based on sam's package.

Anyway, thanks for the support both here and @IRC !
Last edit: 3 years 5 months ago by frederikprijck.

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!