- Posts: 62
- Thank you received: 3
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
RemoteControl 2 API, get attribute from participant table
- Maverick87Shaka
- Topic Author
- Offline
- Senior Member
Less
More
7 years 7 months ago #139825
by Maverick87Shaka
RemoteControl 2 API, get attribute from participant table was created by Maverick87Shaka
Hi,
I'm little bit confused about the use of: "get_participant_properties()"
I'm actually working on a PHP script that are called after the end of a survey. I'm using the javascript function using the get option to pass the attribute that I need to the script.
I would like to switch from this approach to the native API call function.
I think I have to use the "get_participant_properties()" but I made some test without success. For example, using this API function how I can get the {TOKEN:FIRSTNAME} ?
I take a look to the documentation here but I don't know how to build the array: $aTokenProperties , that should be identify the information that I need, for example the FIRSTNAME.
There is some example that I can follow?
Thanks
I'm little bit confused about the use of: "get_participant_properties()"
I'm actually working on a PHP script that are called after the end of a survey. I'm using the javascript function using the get option to pass the attribute that I need to the script.
I would like to switch from this approach to the native API call function.
I think I have to use the "get_participant_properties()" but I made some test without success. For example, using this API function how I can get the {TOKEN:FIRSTNAME} ?
I take a look to the documentation here but I don't know how to build the array: $aTokenProperties , that should be identify the information that I need, for example the FIRSTNAME.
There is some example that I can follow?
Thanks
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
7 years 7 months ago - 7 years 7 months ago #139868
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 RemoteControl 2 API, get attribute from participant table
As a quick example, something like this should work in LS 2.50:
Code:
require_once 'jsonRPCClient.php'; define( 'LS_BASEURL', 'http://pathTo/limeSurvey/'); define( 'LS_USER', 'admin' ); define( 'LS_PASSWORD', 'password' ); define( 'LS_DB_HOST', 'localhost' ); define( 'LS_DB_NAME', 'limesurveyDB' ); define( 'LS_DB_USER', 'limesurveyuser' ); define( 'LS_DB_PASS', 'password' ); define( 'LS_DB_TABLEPREFIX', 'lime_' ); $iSurveyID = $_GET["iSurveyID"]; $token = $_GET["token"]; // 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 ); // Define some params $aTokenQueryProperties = array('token'=>$token); $aTokenProperties = array('email', 'firstname', 'lastname', 'token', 'tid'); $participantProperties = $myJSONRPCClient->get_participant_properties( $sSessionKey, $iSurveyID, $aTokenQueryProperties, $aTokenProperties); // Print the results echo '<ul> <li>Token ID: '.$participantProperties['tid'].'</li> <li>Email: '.$participantProperties['email'].'</li> <li>First name: '.$participantProperties['firstname'].'</li> <li>Last name: '.$participantProperties['lastname'].'</li> <li>Token - '.$participantProperties['token'].'</li> </ul>'; // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey );
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 7 months ago by tpartner.
The topic has been locked.
- Maverick87Shaka
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 62
- Thank you received: 3
7 years 7 months ago #139945
by Maverick87Shaka
Replied by Maverick87Shaka on topic RemoteControl 2 API, get attribute from participant table
Hi,
First of all, Thanks for your support
Your example it's very helpful, even if I have a "big" question.
I'll try the code that you have posted, and it's works but I have to use TID instead token as $aTokenQueryProperties.
It is normal? on the documentation the $aTokenQueryProperties doesn't have any description and I don't if it's a problem of my limesurvey installation.
Actually my script is ignoring at all the TID, because it's working on TOKEN, there is a way to call this get_participant_properties directly using the TOKEN?
If it's not possible, how to quickly get the TID from token?
Thanks in advance.
First of all, Thanks for your support
Your example it's very helpful, even if I have a "big" question.
I'll try the code that you have posted, and it's works but I have to use TID instead token as $aTokenQueryProperties.
It is normal? on the documentation the $aTokenQueryProperties doesn't have any description and I don't if it's a problem of my limesurvey installation.
Actually my script is ignoring at all the TID, because it's working on TOKEN, there is a way to call this get_participant_properties directly using the TOKEN?
If it's not possible, how to quickly get the TID from token?
Thanks in advance.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
7 years 7 months ago #139946
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 RemoteControl 2 API, get attribute from participant table
I don't understand the question. My example does use the token to retrieve the participant properties.... there is a way to call this get_participant_properties directly using the TOKEN?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Maverick87Shaka
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 62
- Thank you received: 3
7 years 7 months ago #139949
by Maverick87Shaka
Replied by Maverick87Shaka on topic RemoteControl 2 API, get attribute from participant table
Your example doesn't work for me if i set token as the $token, it works if I set TID as $token.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
7 years 7 months ago #139952
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 RemoteControl 2 API, get attribute from participant table
My example is for version 2.5. What version are you using?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Maverick87Shaka
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 62
- Thank you received: 3
7 years 7 months ago #139961
by Maverick87Shaka
here is the code that I'm using:
And here is the output: ( value passed by url )
Replied by Maverick87Shaka on topic RemoteControl 2 API, get attribute from participant table
The version is 2.50+ Build 160620tpartner wrote: My example is for version 2.5. What version are you using?
here is the code that I'm using:
Code:
<?php error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); echo "test page to show data: <br>"; require_once 'Classes/jsonRPCClient.php'; include('/sw/LimeSurvey/config.php'); // file wehere I have sotred LS_PASSWORD,LS_USER,LS_BASEURL $iSurveyID = $_GET["iSurveyID"]; $token = $_GET["token"]; echo "received survey ID:".$iSurveyID."<br>"; echo "received token:".$token; // Instantiate a new RPC client $myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/admin/remotecontrol' ); // Get a session key $sSessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD ); // Define some params $aTokenQueryProperties = array('token'=>$token); $aTokenProperties = array('email', 'firstname', 'lastname', 'token', 'tid'); $participantProperties = $myJSONRPCClient->get_participant_properties( $sSessionKey, $iSurveyID, $aTokenQueryProperties, $aTokenProperties); echo "<br>"; print_r ($participantProperties); echo "<br>"; // Print the results echo '<ul> <li>Token ID: '.$participantProperties['tid'].'</li> <li>Email: '.$participantProperties['email'].'</li> <li>First name: '.$participantProperties['firstname'].'</li> <li>Last name: '.$participantProperties['lastname'].'</li> <li>Token - '.$participantProperties['token'].'</li> </ul>'; // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); ?>
And here is the output: ( value passed by url )
The following user(s) said Thank You: riasilva
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
7 years 7 months ago - 7 years 7 months ago #139968
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 RemoteControl 2 API, get attribute from participant table
I'm sorry, I cannot help with that error because I cannot reproduce it.
If you need to use the TID, you can access it via the list_participants() method .
If you need to use the TID, you can access it via the list_participants() method .
Code:
// Find the TID of a token $aConditions = array('token' => $token); $participants = $myJSONRPCClient->list_participants($sSessionKey, $iSurveyID, 0, 1, true, '', $aConditions); $tid = $participants[0]['tid']; echo 'TID: '.$tid;
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 7 months ago by tpartner.
The following user(s) said Thank You: Maverick87Shaka
The topic has been locked.
- Maverick87Shaka
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 62
- Thank you received: 3
7 years 7 months ago #140033
by Maverick87Shaka
With your last coded posted I've successfully managed to get de TID from token, so now I've all the data that I need, thanks
Replied by Maverick87Shaka on topic RemoteControl 2 API, get attribute from participant table
I try also on another ( little bit older ) installation of limesurvey, and works in the same way using TID instead token.tpartner wrote: I'm sorry, I cannot help with that error because I cannot reproduce it.
If you need to use the TID, you can access it via the list_participants() method .
Code:// Find the TID of a token $aConditions = array('token' => $token); $participants = $myJSONRPCClient->list_participants($sSessionKey, $iSurveyID, 0, 1, true, '', $aConditions); $tid = $participants[0]['tid']; echo 'TID: '.$tid;
With your last coded posted I've successfully managed to get de TID from token, so now I've all the data that I need, thanks
The topic has been locked.