Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Get survey questions and answer options using RPC

  • frederikprijck
  • frederikprijck's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 1 month 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.
The topic has been locked.
  • frederikprijck
  • frederikprijck's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 1 month ago - 8 years 1 month ago #131969 by frederikprijck
Replied by frederikprijck on topic Get survey questions and answer options using RPC
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: 8 years 1 month ago by frederikprijck.
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
8 years 1 month 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: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
  • frederikprijck
  • frederikprijck's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 1 month ago - 8 years 1 month ago #131984 by frederikprijck
Replied by frederikprijck on topic Get survey questions and answer options using RPC
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: 8 years 1 month ago by frederikprijck.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #131988 by DenisChenu
Replied by DenisChenu on topic Get survey questions and answer options using RPC

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 , plugin development .
I don't answer to private message.
The topic has been locked.
  • frederikprijck
  • frederikprijck's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 1 month ago - 8 years 1 month ago #131989 by frederikprijck
Replied by frederikprijck on topic Get survey questions and answer options using RPC
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: 8 years 1 month ago by frederikprijck.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose