What data format for "add_response" parameter (RPC)

4 years 3 weeks ago #93094 by mfaber
Fellow users and experts,

I'm stuck trying to add a response to the database using a PHP-script and the RPC-function "add_response". I can't make it work, partly because I do not know what the data format (the array containing the responses) should have. I looked up and down and can't find a working example of code/data.

Background: I want to find a way to take surveys offline. So far I export a survey-page (questions all on one page) and change the html form/post command in the html so the answers are mailed "action=mailto:email@email.org". That is: saved in the email-program until the device is online again and then mailed. My plan is to import these mailed answers using an RPC command.

Any advice or example code would be greatly appreciated!

Please Log in to join the conversation.

4 years 3 weeks ago #93101 by mdekker
By looking at the code I think the responsedata should be an array using the fieldnames from the survey_xxxxx table as keys and the answers as values. So the key should be the sidXgidXqid code, that would be a little hard to implement, but I think there is something in the documentation wiki that explains this code and you can always look at the table structure.

I am not really sure if the procedure is tested to work, what kind of response do you get?

Menno Dekker
The following user(s) said Thank You: mfaber

Please Log in to join the conversation.

4 years 3 weeks ago #93110 by mfaber
Thanks for your help, mdekker...i will try as soon as I'm back on my test environment.

The output from a one-question survey (which I rerouted from the html form POST-command) looks as follows:

So, first the fieldnames (which already come in the old SGQ-structure. Then the fieldnames and answers and then some logic-related and survey specific data. So I should be able to make this work, at least for smaller surveys.

There seems to be a lot of demand for an offline-solution for limesurvey. There are a lot of these freelancer-websites with such requests and offers. Unfortunately none of them have made it into the official limesurvey code.

Please Log in to join the conversation.

4 years 3 weeks ago #93159 by mfaber
It works pretty well using the array structure you suggested. And the data from the POST command can easily be converted to an associative array using the parse_str PHP function.
// convert string to an associative array
parse_str($post, $output);
// does it look ok?
//add response to the LS database
$responseadded=$myJSONRPCClient->add_response($sSessionKey, $survey_id, $output);
// show the reponse code

LS's add_response function is just a a bit picky on what to receive as responses. It unfortunatly reacts with a fatal error if something unexpected is contained in the response array. (see bug report: bugs.limesurvey.org/view.php?id=7629 )

Otherwise, i am confident I can make this offline survey solution work.
Will keep you posted.
Thanks again,
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

4 years 2 weeks ago #93229 by mdekker
I am sure a lot of people would be interested in your solution. If possible, could you add it to our documentation wiki in the workarounds section?


Menno Dekker

Please Log in to join the conversation.

4 years 2 weeks ago #93270 by mfaber
Will do.
I just want to finish writing a script that can handle uploading multiple response files and avoids uploading data that already exist in the LS DB. It was 15 years ago that I last worked as a programmer and I am just learning a bit of PHP through limesurvey. So everything is going a bit slower than I want it to be.... :-).

Please Log in to join the conversation.

3 years 8 months ago #98356 by madflow
I am trying to consume the same exact method in my .Net Application.
But everytime i am getting Result = null.

Paramater that I am passing using Json RPC
{"jsonrpc":"1.0","id":"1","method":"Add_Reponse","params":{"sessionkey":"ABCD","surveyID":"919472","aResponseData":{"submitdate":"07/22/2013","lastpage":"1","startlanguage":"en","919472X6X10":"Y","919472X6X11":"my feedback to you","919472X6X12":"4"}}}

Also i tried the following
{"jsonrpc":"1.0","id":"1","method":"Add_Reponse","params":{"sessionkey":"ABCD","surveyID":"919472","aResponseData":{"919472X6X10":"Y","919472X6X11":"my feedback to you","919472X6X12":"4"}}}
But the Survey response is not getting Added.

The Survey is an Open ended one.

Any pointers as to how to get it working.

Please Log in to join the conversation.