- Posts: 9
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
RPC API, list_participants and filter result by custom attribute
- TonyMonast
- Topic Author
- Offline
- New Member
Less
More
3 years 8 months ago #203363
by TonyMonast
RPC API, list_participants and filter result by custom attribute was created by TonyMonast
Hi,
I want to use the RPC API to get all the participants of a survey with a specific custom attribute value. I found this :
I'm able to call it and get all the participants, but when I try to use the conditions argument, I always get null as a result.
1. Is that possible to filter the participants by attribute by using the conditions argument of list_participants?
2. What is the syntax?
Thank you
I want to use the RPC API to get all the participants of a survey with a specific custom attribute value. I found this :
Code:
list_participants(string $sSessionKey,integer $iSurveyID,integer $iStart,integer $iLimit = 10,boolean $bUnused = false,boolean|array $aAttributes = false,array $aConditions = array()): array
I'm able to call it and get all the participants, but when I try to use the conditions argument, I always get null as a result.
1. Is that possible to filter the participants by attribute by using the conditions argument of list_participants?
2. What is the syntax?
Thank you
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
3 years 8 months ago - 3 years 8 months ago #203392
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic RPC API, list_participants and filter result by custom attribute
Here is a PHP example. In this case, all tokens with a last name of 'Doe' and an attribute_1 value of 'xyz' will be returned.
Also, since $aAttributes is defined, the values for attribute_1 and attribute_2 will be returned for each of those tokens.
Also, since $aAttributes is defined, the values for attribute_1 and attribute_2 will be returned for each of those tokens.
Code:
<?php require_once 'jsonRPCClient.php'; define( 'LS_BASEURL', 'http://pathTo/limeSurvey'); define( 'LS_USER', 'admin' ); define( 'LS_PASSWORD', 'password' ); $iSurveyID = 123456; if(ctype_alnum($iSurveyID) && (strlen($iSurveyID) == 5 || strlen($iSurveyID) == 6)) { // Valid SID format // Instantiate a new RPC client $myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' ); // Get a session key $sSessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD ); if(is_array($sSessionKey)) { // Invalid session echo $sSessionKey['status']; } else if($sSessionKey) { // Valid session // Define the additional attributes to be returned $aAttributes = array('attribute_1', 'attribute_2'); // Define filters for participants $aConditions = array('lastname'=>'Doe', 'attribute_1'=>'xyz'); // Get the filtered participants $participants = $myJSONRPCClient->list_participants($sSessionKey, $iSurveyID, 0, 10, false, $aAttributes, $aConditions); // Print the results echo '<ul>'; foreach($participants as $key => $value) { echo '<li>'; print_r($value); echo '</li>'; } echo '</ul>'; } // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); } else { // Invalid SID format die( 'Invalid format!' ); } ?>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 8 months ago by tpartner.
The following user(s) said Thank You: TonyMonast
The topic has been locked.
- TonyMonast
- Topic Author
- Offline
- New Member
Less
More
- Posts: 9
- Thank you received: 1
3 years 8 months ago #203394
by TonyMonast
Replied by TonyMonast on topic RPC API, list_participants and filter result by custom attribute
There is no indication in the documentation that the conditions argument is an associative array (arrays with named keys). It would be relevant to mention it.
Thank you tpartner for your help! It works!
Thank you tpartner for your help! It works!
The topic has been locked.
- DenisChenu
- Away
- LimeSurvey Community Team
Less
More
- Posts: 13645
- Thank you received: 2491
3 years 8 months ago #203463
by DenisChenu
2. If it's really unclear : all doc come from phpDoc
3. Then you can create pull request : github.com/LimeSurvey/LimeSurvey/blob/cd...rol_handle.php#L2071
Seems clear enough here ?
«Optional conditions to limit the list, e.g. with array('email' => 'info@example.com') or array('validuntil' => array('>', '2019-01-01 00:00:00'))»
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic RPC API, list_participants and filter result by custom attribute
1. wiki and code can be improved by user …TonyMonast wrote: There is no indication in the documentation that the conditions argument is an associative array (arrays with named keys). It would be relevant to mention it.
2. If it's really unclear : all doc come from phpDoc
3. Then you can create pull request : github.com/LimeSurvey/LimeSurvey/blob/cd...rol_handle.php#L2071
Seems clear enough here ?
«Optional conditions to limit the list, e.g. with array('email' => 'info@example.com') or array('validuntil' => array('>', '2019-01-01 00:00:00'))»
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- TonyMonast
- Topic Author
- Offline
- New Member
Less
More
- Posts: 9
- Thank you received: 1
3 years 8 months ago #203486
by TonyMonast
Replied by TonyMonast on topic RPC API, list_participants and filter result by custom attribute
Yes, it's clear enough! Thank you!
The topic has been locked.