- Posts: 9
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Delete participant by survey access token
- TonyMonast
-
Topic Author
- Offline
- New Member
-
Less
More
2 years 7 months ago #204483
by TonyMonast
Delete participant by survey access token was created by TonyMonast
Hi,
I'm trying to find the best solution to connect the platform to our event ticketing application.
Each time a customer goes to purchase an event ticket, they will be allowed to complete a survey later. To access the survey, they will need to use the ticket serial number.
1. When purchasing, we can easily add the participant with add_participants.
2. When canceling the ticket in our app, the participant must be deleted in Lime Survey. However, the API function delete_participants needs the participant's tid (not the token). This gives me the impression that I must first retrieve the list of all survey participants with the API, find the participant with the token linked to the ticket serial number, retrieve the tid, then call the function delete_participants with the tid.
Isn't there a more efficient way to sync all this?
Note : I could also periodically remove all unused participants from the survey, then send the new list of participants, but I would like to be able to do the synchronization with each transaction so that it is as much as possible in real time and using the minimum of ressources.
Any idea is welcome.
Thank you
I'm trying to find the best solution to connect the platform to our event ticketing application.
Each time a customer goes to purchase an event ticket, they will be allowed to complete a survey later. To access the survey, they will need to use the ticket serial number.
1. When purchasing, we can easily add the participant with add_participants.
2. When canceling the ticket in our app, the participant must be deleted in Lime Survey. However, the API function delete_participants needs the participant's tid (not the token). This gives me the impression that I must first retrieve the list of all survey participants with the API, find the participant with the token linked to the ticket serial number, retrieve the tid, then call the function delete_participants with the tid.
Isn't there a more efficient way to sync all this?
Note : I could also periodically remove all unused participants from the survey, then send the new list of participants, but I would like to be able to do the synchronization with each transaction so that it is as much as possible in real time and using the minimum of ressources.
Any idea is welcome.
Thank you
The topic has been locked.
2 years 7 months ago - 2 years 7 months ago #204485
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 Delete participant by survey access token
Yes, you will need to make two API calls.
The list_participants() function can be filtered by the token value:
The list_participants() function can be filtered by the token value:
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 // Filter by token value $aConditions = array('token'=>'123456789'); // Get the filtered participants $participants = $myJSONRPCClient->list_participants($sSessionKey, $iSurveyID, 0, 10, false, false, $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: 2 years 7 months ago by tpartner.
The following user(s) said Thank You: TonyMonast
The topic has been locked.
2 years 7 months ago - 2 years 7 months ago #204486
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 Delete participant by survey access token
...or, for your use-case:
Code:
<?php require_once 'jsonRPCClient.php'; define( 'LS_BASEURL', 'http://pathTo/limeSurvey'); define( 'LS_USER', 'admin' ); define( 'LS_PASSWORD', 'password' ); $iSurveyID = 123456; $token = 123456789; 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 // Filter by token value $aConditions = array('token'=>$token); // Get the filtered participants $participants = $myJSONRPCClient->list_participants($sSessionKey, $iSurveyID, 0, 10, false, false, $aConditions); // Now, delete the first returned participant $aTokenIDs = array($participants[0]['tid']); $deleteParticipants = $myJSONRPCClient->delete_participants($sSessionKey, $iSurveyID, $aTokenIDs); } // 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: 2 years 7 months ago by tpartner.
The topic has been locked.
- TonyMonast
-
Topic Author
- Offline
- New Member
-
Less
More
- Posts: 9
- Thank you received: 1
2 years 7 months ago #204488
by TonyMonast
Replied by TonyMonast on topic Delete participant by survey access token
Interesting! I suppose the filter by token value allow you to only get one participant? Is there any way to get a list of participants from a list of tokens? The idea is if a user cancel 100 event tickets, I don't want to do this operation 100 times, but just one.
I suppose I need to get all the participants from Lime Survey then filter it on the application side, right?
I suppose I need to get all the participants from Lime Survey then filter it on the application side, right?
The topic has been locked.
2 years 7 months ago - 2 years 7 months ago #204489
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 Delete participant by survey access token
[strike]Yes, since tokens are unique, the "token" condition can only match one result.[/strike]I suppose the filter by token value allow you to only get one participant?
Not sure I understand this. With filtering on the API call, you will only get one participantI suppose I need to get all the participants from Lime Survey then filter it on the application side, right?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 2 years 7 months ago by tpartner.
The topic has been locked.
2 years 7 months ago #204490
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 Delete participant by survey access token
Oh, wait, the list_participants() function accepts an array for token values in the $aConditions parameter:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.