What data format for "add_response" parameter (RPC)

More
4 years 3 months ago #93094 by mfaber
mfaber created the topic: What data format for "add_response" parameter (RPC)
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.

More
4 years 2 months ago #93101 by mdekker
mdekker replied the topic: What data format for "add_response" parameter (RPC)
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.

More
4 years 2 months ago #93110 by mfaber
mfaber replied the topic: What data format for "add_response" parameter (RPC)
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:
fieldnames=171217X171X1634&171217X171X1634=N&java171217X171X1634=N&relevance1634=1&relevanceG0=1&move=movesubmit&thisstep=2&sid=171217&start_time=1361740277&LEMpostKey=1502713047

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.

More
4 years 2 months ago #93159 by mfaber
mfaber replied the topic: What data format for "add_response" parameter (RPC)
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.
$post="542856X167X1616=Y&542856X168X1617=12&542856X168X1618=F&542856X168X1619=6&542856X169X1620=Y&542856X169X1621=&542856X169X1622SQ001=Y&542856X169X1622SQ002=U&542856X169X1622SQ003=N&542856X169X1622SQ004=Y&542856X169X1622SQ005=U&542856X170X1623=Y&542856X170X1624SQ001=Y&542856X170X1624SQ002=U&542856X170X1624SQ003=N&542856X170X1624SQ004=";
 
// convert string to an associative array
parse_str($post, $output);
 
// does it look ok?
print_r($output);
 
//add response to the LS database
$responseadded=$myJSONRPCClient->add_response($sSessionKey, $survey_id, $output);
 
// show the reponse code
print_r($responseadded);


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,
M
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

More
4 years 2 months ago #93229 by mdekker
mdekker replied the topic: What data format for "add_response" parameter (RPC)
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?

docs.limesurvey.org/Workarounds&structur...tions+for+LimeSurvey

---
Menno Dekker

Please Log in to join the conversation.

More
4 years 2 months ago #93270 by mfaber
mfaber replied the topic: What data format for "add_response" parameter (RPC)
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.

More
3 years 10 months ago #98356 by madflow
madflow replied the topic: What data format for "add_response" parameter (RPC)
Hi,
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.

Start now!

Just create your account and start using Limesurvey today.

Register now