Welcome to the LimeSurvey Community Forum

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

Problem setting token value through RemoteControl 2

  • horseshrink
  • horseshrink's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 11 months ago #152709 by horseshrink
This is my first time to post in this forum. Not a professional programmer, but am taking a graduate Python course and have been spending regular time over the past several months developing a clinical diagnostic interview with LimeSurvey.

There are three LimeSurvey interview modules. I've written code to export the answers from each module and massage them into one final product suitable for copy/pasting into an electronic health record. "export_responses_by_token" is working well using JSON.

Am trying to get another Python module written for office staff to input a token number and patient name, using these to initialize one participant for all three LimeSurvey interview modules. I want the token number to be the patient's medical record number.

However, I can't seem to set the token value via the "add_participants" API method. I've run this through my code and Lindsay Stevens code with similar results. The "add_participants" command works fully, successfully adding participants to all three interview modules ... but the tokens are automatically generated as random values rather than accepting the token value I'm trying to set.

Using Version 2.64.7+170404

Have tried the following parameter strings with no joy (various combinations of bCreateToken values and use of integers vs. strings):


{"method": "add_participants", "params": {"sSessionKey": "xnwizxpv25n2upzei9xjbr9866h6hrjk", "iSurveyID": 556469, "aParticipantData": [{"token": 9876543, "firstname": "Frank", "lastname": "Smith", "participant_id": 9876543, "tid": 9876543}], "bCreateToken": "false"}, "id": 1}

{"method": "add_participants", "params": {"sSessionKey": "ga9e7cwsn3ce53zfjmihdgkh4qd8456q", "iSurveyID": 556469, "aParticipantData": [{"token": 9876543, "firstname": "Frank", "lastname": "Smith", "participant_id": 9876543, "tid": 9876543}], "bCreateToken": "true"}, "id": 1}

{"method": "add_participants", "params": {"sSessionKey": "a38yj6mpse8bsp9v3wbttc65aim73qm8", "iSurveyID": 556469, "aParticipantData": [{"token": "9876543", "firstname": "Frank", "lastname": "Smith", "participant_id": "9876543", "tid": "9876543"}], "bCreateToken": "true"}, "id": 1}

{"method": "add_participants", "params": {"sSessionKey": "n78jn7fitdkt27t6td9xsmpujbxn8yht", "iSurveyID": 556469, "aParticipantData": [{"token": "9876543", "firstname": "Frank", "lastname": "Smith", "participant_id": "9876543", "tid": "9876543"}], "bCreateToken": "false"}, "id": 1}



These all work (I delete the newly created participants between trial runs) ... except for the token still being automatically generated instead of manually set.
Am worried I'm just missing something very obvious.
The topic has been locked.
More
6 years 11 months ago - 6 years 11 months ago #152711 by Ben_V
Hello and welcome...

you may find some inspiration in the php scripts provided by Tony (@tpartner) where the token value is defined in a $aParticipantData array:

www.limesurvey.org/forum/can-i-do-this-w...api-add_participants

( same script sending email to the participant )

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Last edit: 6 years 11 months ago by Ben_V.
The topic has been locked.
  • horseshrink
  • horseshrink's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 11 months ago #152722 by horseshrink
Replied by horseshrink on topic Problem setting token value through RemoteControl 2
Thank you. I'd actually looked over those same posts a number of times in trying to figure this out. Couldn't figure out how to change anything I've already tried from that. Looks like Tony(@partner) supplies the same info I do. The frustration is that I successfully add participants, including names, etc. My only glitch is the token being generated automatically instead of being set in the manner that I specify.
The topic has been locked.
  • horseshrink
  • horseshrink's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 11 months ago #152731 by horseshrink
Replied by horseshrink on topic Problem setting token value through RemoteControl 2
In case useful, the associated Python code:

participantdata = [{'token': token, 'firstname': firstname, 'lastname': lastname, 'participant_id': token, 'tid': token, 'language': 'en'}]

token_params = OrderedDict([('SessionKey', session_key), ('SurveyID', 0),
('aParticipantData', participantdata), ('bCreateToken', 'True')])

set_tokens = OrderedDict([('method', 'add_participants'),
('params', token_params), ('id', 1)])

tokens_json = json.dumps(set_tokens)

for survey in survey_list:
token_params = survey
tokens_json = json.dumps(set_tokens)
response = requests.post(url, headers=headers, data=tokens_json)
return_value = response.json()
if return_value:
print("%s survey did not initialize. Error: %s" % (survey, return_value))
else:
for k, v in return_value.items():
if k == 'result':
toke = v[0]
print("Survey %s initiated for %s %s, token number: %s" % (survey, firstname, lastname, toke))
The topic has been locked.
  • horseshrink
  • horseshrink's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 11 months ago #152732 by horseshrink
Replied by horseshrink on topic Problem setting token value through RemoteControl 2
Code didn't post with indents. Noticed code posting icon afterwards, but there's not one for Python anyway. Screenshot here .
The topic has been locked.
More
6 years 11 months ago - 6 years 11 months ago #152751 by Ben_V

horseshrink wrote: Thank you. I'd actually looked over those same posts a number of times in trying to figure this out.



A big difference in your code is the use of
$bCreateToken = true;

try with:
$bCreateToken = 0;

...as also suggested here:
www.limesurvey.org/forum/future-features...icipant-table#111283

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Last edit: 6 years 11 months ago by Ben_V.
The topic has been locked.
  • horseshrink
  • horseshrink's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 11 months ago #152755 by horseshrink
Replied by horseshrink on topic Problem setting token value through RemoteControl 2
Way cool!!!! Thx, Ben! That worked.

This is not apparent from the documentation.
I wonder if documentation should be clarified?
The topic has been locked.
More
6 years 11 months ago #152980 by Ben_V

horseshrink wrote: This is not apparent from the documentation.
I wonder if documentation should be clarified?


Limesurvey documentation is a wiki and any user can edit it with the same login credentials used for forum.
It could be very nice if you can add some precision... if you already know where!

BTW, this "bCreateToken" issue could be a bug and you can also report it in the bugtracker. If confirmed, this will be corrected for the next release.

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.
  • horseshrink
  • horseshrink's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 11 months ago #153049 by horseshrink
Replied by horseshrink on topic Problem setting token value through RemoteControl 2
Thank you. Will run the script a couple of other ways to clarify which parameters work/don't work for bCreateToken before doing as you suggest with the wiki and Bugtracker.
The following user(s) said Thank You: Ben_V
The topic has been locked.
  • horseshrink
  • horseshrink's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 11 months ago #153115 by horseshrink
Replied by horseshrink on topic Problem setting token value through RemoteControl 2
So, it was a simple issue. Yes, zero works (again, many thanks!).

False also works ... but I had it submitted as a string, rather than as a Boolean value.

So, 'False' doesn't work. False (no quotes) does.
The following user(s) said Thank You: Ben_V
The topic has been locked.
More
6 years 11 months ago #153117 by Ben_V
Sounds logical now and bug free... Thank you for those feedback and explanation .

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose