Welcome to the LimeSurvey Community Forum

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

set_participant_properties

  • mama0107
  • mama0107's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 2 months ago #162940 by mama0107
set_participant_properties was created by mama0107
I work with version 2.62 of the Limesurvey. I would like to manage my survey with a small Java program. I use jdk1.8.0_91 and RemoteControl with json.


With this function, I export a participant property from a LimeSurvey survey

new StringEntity("{\"method\": \"get_participant_properties\", \"params\": {\"sSessionKey \": \""+sessionKey+"\", \"iSurveyId \": \""+surveyid+"\", \"iTokenId\":\""+participant_id+"\" }, \"id\": 1}");
or

new StringEntity("{\"method\": \"get_participant_properties\", \"params\": [ \""+sessionKey+"\", \""+surveyid+"\", \""+participant_id+"\" ], \"id\": 1}");

result

{"id":1,"result":{"tid":2,"participant_id":null,"firstname":"","lastname":"","email":"","emailstatus":"OK","token":"mB755ZDQfd","language":"de","blacklisted":null,"sent":"N","remindersent":"N","remindercount":0,"completed":"N","usesleft":1,"validfrom":null,"validuntil":null,"mpid":null},"error":null}




If I want to change a properties for a participant, then I only get error messages.

new StringEntity("{\"method\": \"set_participant_properties\", \"params\": [ \""+sessionKey+"\", \""+surveyid+"\", \""+participant_id+"\", \"language\":\"es\" ], \"id\": 94}");

result

{"id":null,"result":null,"error":"unable to decode malformed json"}

or

new StringEntity("{\"method\": \"set_participant_properties\", \"params\": [ \""+sessionKey+"\", \""+surveyid+"\", \""+participant_id+"\", \""+aTokenProperties+"\" ], \"id\": 194}");

result

ERROR StatusCode 500

How can I pass the argument $aTokenData?


Best regards Cornelia
The topic has been locked.
  • LouisGac
  • LouisGac's Avatar
  • Visitor
  • Visitor
6 years 2 months ago #162942 by LouisGac
Replied by LouisGac on topic set_participant_properties
The method can be found here:
github.com/LimeSurvey/LimeSurvey/blob/2....ndle.php#L1630-L1674

Code:
public function get_participant_properties($sSessionKey, $iSurveyID, $iTokenID, $aTokenProperties)


And as you can see:
github.com/LimeSurvey/LimeSurvey/blob/2....rol_handle.php#L1657
Code:
                $result = array_intersect_key($token->attributes, array_flip($aTokenProperties));
 


the param $aTokenProperties is used for a array_flip function
php.net/manual/en/function.array-flip.php

Note that the values of array need to be valid keys, i.e. they need to be either integer or string. A warning will be emitted if a value has the wrong type, and the key/value pair in question will not be included in the result.



That doesn't explain why you have an error 500.
I suggest you do some test on the method, maybe you'll find a bug.
Feel free to submit PR to our Git Repository.
The topic has been locked.
  • mama0107
  • mama0107's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 2 months ago #162945 by mama0107
Replied by mama0107 on topic set_participant_properties
Thank you for your prompt reply.

For the argument $aTokenProperties I tried different java data types.
HashMap<String, String>
Hashtable<String, String>
ArrayList<String>


But without success
The topic has been locked.
  • LouisGac
  • LouisGac's Avatar
  • Visitor
  • Visitor
6 years 2 months ago #162948 by LouisGac
Replied by LouisGac on topic set_participant_properties
Google: "Java LimeSurvey Remote control"

github.com/Falydoor/limesurvey-rc/blob/m...veyRC.java#L384-L393

LimeSurvey is OpenSource. Most of the time, when you want to do something, someone else already did it. So rather than doing everything from scratch again and again (like in privative software logic), it's always better to use and modify what others did.
The topic has been locked.
  • mama0107
  • mama0107's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 2 months ago #163040 by mama0107
Replied by mama0107 on topic set_participant_properties

That doesn't explain why you have an error 500.
I suggest you do some test on the method, maybe you'll find a bug.
Feel free to submit PR to our Git Repository.



The set_participant_properties function is included in the remotecontrol_handle.php file.
When evaluating $aTokenData, error 500 occurs.

Json is valid
{
"method": "set_participant_properties", "params": ["vkedvegpz6gudave9nyhy9earqb4jcm4",
"479983", "2", "[language, value1]"], "id": 95
}

But I am not a PHP programmer and take too long to fully understand the project.
That is why I do not change source code.

Best regards Cornelia
The topic has been locked.
  • LouisGac
  • LouisGac's Avatar
  • Visitor
  • Visitor
6 years 2 months ago #163041 by LouisGac
Replied by LouisGac on topic set_participant_properties
github.com/Falydoor/limesurvey-rc/blob/m...veyRC.java#L384-L393

Seems that this java coder managed to get it working
The topic has been locked.
More
5 years 2 days ago #183408 by snakeriot
Replied by snakeriot on topic set_participant_properties
This thread is pretty old, but I spent a lot of time searching for the answers on questions asked here, and not found them.
As result, after almost whole day in Lime Survey code and experiments with an API - I have answers:

In order to make this method work - your string should look like this:
Code:
"{\"method\": \"set_participant_properties\", \"params\": {\"sSessionKey \": \"{0}\", \"iSurveyID \": \"{1}\", \"aTokenQueryProperties\": {\"token\": \"{2}\"}, \"aTokenData \": {\"sent\": \"Y\"}}, \"id\": \"1\"}"

Where:
* {0} - Session Key
* {1} - Survey ID
* {2} - Token of the participant

Instead of token, in "aTokenQueryProperties" you can use any fields from this documentation (properties section), the only condition is that whole set of fields should point to Only one Participant, in other case you will get "Error: More than 1 result was found based on your attributes.".

Same list of attributes is accepted by "aTokenData" field.

As I can see from the implementation on Lime Survey side - there is no way to update multiple participants using same request:
Code:
$tokenCount = Token::model($iSurveyID)->countByAttributes($aTokenQueryProperties);
if($tokenCount == 0){
  return array('status' => 'Error: No results were found based on your attributes.');
}else if($tokenCount > 1){
  return array('status' => 'Error: More than 1 result was found based on your attributes.');
}

Hope that this information will save someone's day :)
The following user(s) said Thank You: tpartner, DivePeak, fellipeguerra1, mama0107, riasilva
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose