- Posts: 55
- Thank you received: 2
Ask the community, share ideas, and connect with other LimeSurvey users!
<?php require_once 'application/libraries/jsonRPCClient.php'; define( 'LS_BASEURL', ' www.pathTo/limesurvey '); define( 'LS_USER', '***' ); define( 'LS_PASSWORD', '***' ); $iSurveyID = 318848; $token = 'ABCDE'; $email = 'example@example.com'; $LastNameAPI = 'Nom famille' ; $FirstNameAPI = 'Prenom' ; // 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 the token params $tokenParams = array("email"=>$email,"lastname"=>$LastNameAPI,"firstname"=>$FirstNameAPI,"token"=>$token,"language"=>'fr',"emailstatus"=>"OK"); $aParticipantData=array($tokenParams); $bCreateToken = true; // Create the tokens $newToken = $myJSONRPCClient->add_participants( $sSessionKey, $iSurveyID, $aParticipantData, $bCreateToken); // Print returned results echo '<hr><br><h1>Limesurvey</h1><br>New token created in survey '.$iSurveyID.':' .'<ul>' .'<li>TID - '.$newToken[0]['tid'].'</li>' .'<li>Token - '.$newToken[0]['token'].'</li>' .'</ul>'; // Send an invitation to the created token $tokenIDs = array($newToken[0]['tid']); $newMail = $myJSONRPCClient->invite_participants($sSessionKey, $iSurveyID, $tokenIDs, true); // Print returned results if($newMail[$newToken[0]['tid']]['status'] == 'OK') { echo 'Invitation sent to:' .'<ul>' .'<li>Name - '.$newMail[$newToken[0]['tid']]['name'].'</li>' .'<li>Email - '.$newMail[$newToken[0]['tid']]['email'].'</li>' .'</ul>'; } else { echo 'Error - no invitation sent!'; } // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); ?>
<?php require_once 'jsonRPCClient.php'; define( 'LS_BASEURL', 'https://pathTo/limeSurvey/'); define( 'LS_USER', 'admin' ); define( 'LS_PASSWORD', 'password' ); $iSurveyID = 123456; // 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 ); // Send an invitation to a token $tokenIDs = array(38); $newMail = $myJSONRPCClient->invite_participants($sSessionKey, $iSurveyID, $tokenIDs, true); // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); ?>