Welcome to the LimeSurvey Community Forum

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

Remote API get_responses not returning all responses

More
9 years 11 months ago #143657 by joost1982
Hi there,

I have a little Python script with the following code to extract al given responses from a survey:
Code:
def export_responsescsv(skey,sid): req = urllib2.Request(url='https://xxxxxxxxxxxx',\ data='{\"method\":\"export_responses\",\"params\":{\"sSessionKey\":\"'+skey+'\",\"iSurveyID\":\"'+sid+'\",\ \"DocumentType\":\"csv\",\"sLanguageCode\":\"en\",\"sHeadingType\":\"full\"},\ "id\": 1}') req.add_header('content-type', 'application/json') req.add_header('connection', 'Keep-Alive') try: f = urllib2.urlopen(req) myretun = f.read() #print myretun j=json.loads(myretun) return j['result'] except : e = sys.exc_info()[0] print ( "<p>Error: %s</p>" % e )

However, only the following variables are extracted:
"id,"submitdate","lastpage","startlanguage","startdate","datestamp","ipaddr".
While my goal is to extract ALL the variables / questions and answers. How can I accomplish that?
The topic has been locked.
More
9 years 11 months ago #143671 by Deusdeorum
Hmm. Are you sure you're actually retrieving anything at all?

Code:
def export_responses(myskey,sid): req = urllib2.Request(url='https://localhost:8080/limesurvey/index.php/admin/remotecontrol',\ data='{\"method\":\"export_responses\",\"params\":{\"sSessionKey\":\"%s\"\ ,\"iSurveyID\":\"%s\",\"DocumentType\":\"csv\",\"sLanguageCode\":\"en\",\ \"sHeadingType\":\"full\"},\"id\": 1}'% (myskey, sid)) req.add_header('content-type', 'application/json') req.add_header('connection', 'Keep-Alive') try: f = urllib2.urlopen(req) myretun = f.read() j=json.loads(myretun) return j['result'] except : e = sys.exc_info()[0] print ( "<p>Error: %s</p>" % e ) data = export_responses(myskey, 925212).decode('base64') df = pd.read_table(StringIO(data), sep=",") print df

This is basically the same example, but with a conversion specifier and not a string concatenation and this will indeed print the result i am expecting:

id submitdate lastpage startlanguage token q1[1] q1[2] \
0 50 NaN NaN en 7Yq13 NaN NaN
1 51 NaN NaN en 7Yq13 NaN NaN
2 52 1980-01-01 00:00:00 1.0 en 7Yq13 1.0 1.0
3 53 1980-01-01 00:00:00 1.0 en _SqM_ 2.0 2.0
4 54 NaN NaN en vZTae NaN NaN
5 55 1980-01-01 00:00:00 1.0 en vZTae 2.0 2.0
6 56 1980-01-01 00:00:00 1.0 en sdsXz 1.0 1.0
7 57 1980-01-01 00:00:00 1.0 en jrSRs 2.0 2.0
8 58 1980-01-01 00:00:00 1.0 en 2MsHu 2.0 2.0
9 59 1980-01-01 00:00:00 1.0 en NMt7e 2.0 2.0
10 60 1980-01-01 00:00:00 1.0 en 8mdWO 2.0 2.0
11 61 1980-01-01 00:00:00 1.0 en eAZIb 2.0 2.0

q2[1] q2[2] q3 q4[1] q4[2] q4[3] q4[4] q4[5]
0 NaN NaN NaN NaN NaN NaN NaN NaN
1 NaN NaN NaN NaN NaN NaN NaN NaN
2 test test 1.0 NaN NaN NaN NaN NaN
3 test test 2.0 NaN NaN NaN NaN NaN
4 NaN NaN NaN NaN NaN NaN NaN NaN
5 test test 2.0 4.0 4.0 4.0 4.0 4.0
6 test test 2.0 5.0 5.0 5.0 5.0 5.0
7 test test 3.0 5.0 5.0 5.0 5.0 5.0
8 te te 2.0 5.0 5.0 5.0 5.0 5.0
9 te te 3.0 5.0 5.0 5.0 5.0 5.0
10 sad asd 1.0 5.0 5.0 5.0 5.0 5.0
11 sad asd 1.0 5.0 5.0 5.0 5.0 5.0

The topic has been locked.
More
9 years 11 months ago #143673 by joost1982
I found the problem. It has something to do with an old copy of Limesurvey.

The Pythonscript works when it communicates with Limesurvey on my work computer, which is a more recent version of Limesurvey (> 2.50).
The same script however is not working on my home computer where I have an old copy of Limesurvey (2.05). Here I only get the variables back which I described in my first post.
The solution is upgrading Limesurvey on my home computer. I did that and now the script returns all the variables.
The topic has been locked.
Moderators: tpartner, holch

Lime-years ahead

Online-surveys for every purse and purpose