- Posts: 72
- Thank you received: 17
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Limesurvey remotecontrol API, python glue
- Deusdeorum
- Topic Author
- Offline
- Senior Member
def list_participants(self, sid, iStart=0, iLimit=100, bUnused='false', aAttributes='false', aConditions=array()): data = """ { "id" : 1, "method":"list_participants", "params": { "sSessionKey": "%s", "iSurveyID": %s, "iStart": %s, "iLimit": %s, "bUnused": "%s", "aAttributes": "%s", "aConditions": "%s" } } """ % (self.session_key, sid, iStart, iLimit, bUnused, aAttributes, aConditions) return self._getJSON(data)['result']
- Deusdeorum
- Topic Author
- Offline
- Senior Member
- Posts: 72
- Thank you received: 17
Adding the following to the list_participants remotecontrol_handle.php will work, but it still feels like i'm calling the API wrong.
Adding:
usesleft'=>$token->attributes['usesleft']
In the python glue case:
Calling the API:
lime.list_participants(sid, iStart=0, iLimit=10000, bUnused='false', aAttributes='usesleft', aConditions=None)
- Deusdeorum
- Topic Author
- Offline
- Senior Member
- Posts: 72
- Thank you received: 17
Deusdeorum wrote: Same goes for the R case, it seems like i'm missing something..
Adding the following to the list_participants remotecontrol_handle.php will work, but it still feels like i'm calling the API wrong.
Adding:under the list_participants in remotecontrol_handle.php will return usesleft as default, but i'm sure i'm calling the API wrongCode:usesleft'=>$token->attributes['usesleft']
In the python glue case:
Calling the API:this will return the defaults: 'participant_info.email', 'participant_info.firstname', 'participant_info.lastname', 'tid', 'token'Code:lime.list_participants(sid, iStart=0, iLimit=10000, bUnused='false', aAttributes='usesleft', aConditions=None)
So after adding
usesleft'=>$token->attributes['usesleft']
- frederikprijck
- Offline
- New Member
- Posts: 14
- Thank you received: 1
- Deusdeorum
- Topic Author
- Offline
- Senior Member
- Posts: 72
- Thank you received: 17
frederikprijck wrote: I got it working in C# => prntscr.com/ar9ykj
Could you share your HTTP headers + body ?
Thanks for your reply, not sure what the HTTP headers and body is, im using the glue on github
How did you manage it to work? No matter which brackets, quotemarks etc I use it still fails to give me extra attributes..
- frederikprijck
- Offline
- New Member
- Posts: 14
- Thank you received: 1
I'm not aware of the python project. But the Remote API is accessed using HTTP, looking at the linked Github project I can tell it's also calling the RPC over HTTP.
To ensure everything is sent to the RPC as expected, it's a good idea to inspect the HTTP headers and body (this is generally a good idea when doing HTTP Requests).
I use fiddler ( www.telerik.com/fiddler ) for this but I'm pretty sure there will be other tools around which can sort you out.
The next thing you should do is make your call to the RPC and make sure it is recorded.
Now you can inspect the body and ensure it has a format as the screenshots attached:
This is the JSON extract of the body of the Http Post Request
{"method":"list_participants", "params":{ "id":1, "sSessionKey":"xxxx", "iSurveyID":111, "iStart":0, "iLimit":100000, "bUnused":false, "aAttributes":["language","completed","usesleft"], "aConditions":{"usesleft":"0"} } }
This is copied from my succesful request.
Apart from inspecting the Request, you can also inspect the response. (See the other attached screenshot)
Here you can see that I succesfully got the 3 extra fields (usesleft, completed and language) for each token.
Also, which version of LimeSurvey are you using ?
- Deusdeorum
- Topic Author
- Offline
- Senior Member
- Posts: 72
- Thank you received: 17
frederikprijck wrote: Hi,
I'm not aware of the python project. But the Remote API is accessed using HTTP, looking at the linked Github project I can tell it's also calling the RPC over HTTP.
To ensure everything is sent to the RPC as expected, it's a good idea to inspect the HTTP headers and body (this is generally a good idea when doing HTTP Requests).
I use fiddler ( www.telerik.com/fiddler ) for this but I'm pretty sure there will be other tools around which can sort you out.
The next thing you should do is make your call to the RPC and make sure it is recorded.
Now you can inspect the body and ensure it has a format as the screenshots attached:
This is the JSON extract of the body of the Http Post RequestCode:{"method":"list_participants", "params":{ "id":1, "sSessionKey":"xxxx", "iSurveyID":111, "iStart":0, "iLimit":100000, "bUnused":false, "aAttributes":["language","completed","usesleft"], "aConditions":{"usesleft":"0"} } }
This is copied from my succesful request.
Apart from inspecting the Request, you can also inspect the response. (See the other attached screenshot)
Here you can see that I succesfully got the 3 extra fields (usesleft, completed and language) for each token.
Also, which version of LimeSurvey are you using ?
Thanks a lot for your clarifications and your reply. Im on the version 2.06+ build 151018.
I'm using fiddler now as a debugger but still can't figure it out.
I have rewritten some python code for the general case (taken mostly from manual.limesurvey.org/RemoteControl_2_API ):
def list_participants(): req = urllib2.Request(url='http://www.myurl.com/index.php/admin/remotecontrol',\ data='{\"method\":\"list_participants\",\"params\":{\"sSessionKey\":\"MYSESSIONKEY\",\"iSurveyID\":MYSID,\"iStart\":0,\"iLimit\":200,\"bUnused\":\"True\",\"aAttributes\":\"usesleft\",\"aConditions\":\"\"},\"id\":1}') 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) print j return j['result'] except : e = sys.exc_info()[0] print ( "<p>Error: %s</p>" % e )
However, both of the methods fails in returning usesleft where both returns the following JSON in fiddler (see picture). You think there could be something on the server side?
- frederikprijck
- Offline
- New Member
- Posts: 14
- Thank you received: 1
'{\"method\""list_participants\",\"params\":{\"sSessionKey\""MYSESSIONKEY\",\"iSurveyID\":MYSID,\"iStart\":0,\"iLimit\":200,\"bUnused\""True\",\"aAttributes\":[\"usesleft\"],\"aConditions\""\"},\"id\":1}'
- Deusdeorum
- Topic Author
- Offline
- Senior Member
- Posts: 72
- Thank you received: 17
Im going to pull request the github
- frederikprijck
- Offline
- New Member
- Posts: 14
- Thank you received: 1
Compare your request data with mine in the attached screenshot ...
If you inspect your request with fiddler, you should see an array now aswell ...
Glad you worked it out !