- Posts: 55
- Thank you received: 2
Ask the community, share ideas, and connect with other LimeSurvey users!
<?php /* * * * * * * * * * * * * * * * * * * * * * * Start Edit * * * * * * * * * * * * * * * * * * * * * */ define( 'LS_BASEURL', 'https://www.vecteursleviers.com/conseil' ); // if subbfolder => https://localhost/MyFolder define( 'LS_USER', '***' ); define( 'LS_PASSWORD', '***' ); $iSurveyId = 318848; // survey ID $sid = 318848; /* * * * * * * * * * * * * * * * * * * * * * * End Edit * * * * * * * * * * * * * * * * * * * * * */ /* using LimeSurvey (LS) RemoteControly API version 2's JSON-RPC method */ include "application/libraries/jsonRPCClient.php"; /* instantiate a new client */ $lsJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' ); /* receive session key */ $sessionKey = $lsJSONRPCClient->get_session_key(LS_USER, LS_PASSWORD); /* receive all ids and info of query belonging to a given survey */ $properties = array('template','datecreated','showwelcome','bounce_email'); $result = $lsJSONRPCClient->call('get_survey_properties', array($sessionKey,$iSurveyId,$properties)); /* output */ print_r($result, null ); /* Code from https://code.uoa.gr/p/limesurvey/test_scenarios.php */ /* Participants Data */ $aParticipantData = array( 'user3'=>array('firstname'=>'Christopher', 'lastname'=>'hitchens', 'email'=>'christopher@example.com', 'language'=>'en', 'emailstatus'=>'ok'), ); /* Add particpants */ $result = $client->call('add_participants', array($sessionkey,$sid,$aParticipantData)); /*List participants */ $result = $client->call('list_participants', array($sessionkey,$sid)); /* End code from https://code.uoa.gr/p/limesurvey/test_scenarios.php */ /* release the session key */ $lsJSONRPCClient->release_session_key($sessionKey); ?>
<?php require_once 'jsonRPCClient.php'; define( 'LS_BASEURL', 'https://pathTo/limeSurvey/'); define( 'LS_USER', 'adminName' ); define( 'LS_PASSWORD', 'password' ); define( 'LS_DB_HOST', 'localhost' ); define( 'LS_DB_NAME', 'limesurvey' ); define( 'LS_DB_USER', 'root' ); define( 'LS_DB_PASS', '' ); define( 'LS_DB_TABLEPREFIX', 'lime_' ); $iSurveyID = 318848; $token = 'ABCDE'; // 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 the token params $tokenParams = array("email"=>"example@example.com","lastname"=>"LastName","firstname"=>"FirstName","token"=>$token,"language"=>'en',"emailstatus"=>"OK"); $aParticipantData=array($tokenParams); $bCreateToken = false; // Create the tokens $newToken = $myJSONRPCClient->add_participants( $sSessionKey, $iSurveyID, $aParticipantData, $bCreateToken); // Print returned results echo 'New token created in survey '.$iSurveyID.':' .'<ul>' .'<li>TID - '.$newToken[0]['tid'].'</li>' .'<li>Token - '.$newToken[0]['token'].'</li>' .'</ul>'; // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); ?>
Could be the trailing "," at the end of this line:jltrussart11 wrote: ]Hi,
I can't manage the add_participant routine to works for a given survey. Anyone have an idea about it?
Thanks in advance for your precious help!