set_participant_properties

More
1 year 4 months ago #162940 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

Please Log in or Create an account to join the conversation.

LimeSurvey Partners
More
1 year 4 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

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


And as you can see:
github.com/LimeSurvey/LimeSurvey/blob/2....rol_handle.php#L1657
                $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.

Please Log in or Create an account to join the conversation.

More
1 year 4 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

Please Log in or Create an account to join the conversation.

More
1 year 4 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.

Please Log in or Create an account to join the conversation.

More
1 year 4 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

Please Log in or Create an account to join the conversation.

More
1 year 4 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

Please Log in or Create an account to join the conversation.

More
2 months 2 days ago #183408 by snakeriot
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:
"{\"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:
$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, fellipeguerra1, mama0107

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!