Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

API: add_participants

  • jltrussart11
  • jltrussart11's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
7 years 2 weeks ago #149674 by jltrussart11
API: add_participants was created by jltrussart11
]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!

Code:
<?php
 
/* * * * * * * * * * * * * * * * * * * * * * 
 * Start Edit
 * * * * * * * * * * * * * * * * * * * * * */
 
define( 'LS_BASEURL', 'http://www.vecteursleviers.com/conseil' ); // if subbfolder => http://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 http://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 http://code.uoa.gr/p/limesurvey/test_scenarios.php */
 
/* release the session key */
$lsJSONRPCClient->release_session_key($sessionKey);
 
?>
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 2 weeks ago #149678 by tpartner
Replied by tpartner on topic API: add_participants
I'm no API expert but something like this works for me:

Code:
<?php
 
  require_once 'jsonRPCClient.php';
 
  define( 'LS_BASEURL', 'http://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 );
?>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: jltrussart11
The topic has been locked.
  • jltrussart11
  • jltrussart11's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
7 years 2 weeks ago #149685 by jltrussart11
Replied by jltrussart11 on topic API: add_participants
Thanks a lot i get it to works with you precious help!

have a nice day!
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
6 years 11 months ago #152295 by Mazi
Replied by Mazi on topic API: add_participants

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!

Could be the trailing "," at the end of this line:
'emailstatus'=>'ok'),

If you have fixed your issue, please always post the updated, correct code for others.

Thanks!

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
  • jltrussart11
  • jltrussart11's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 11 months ago #152317 by jltrussart11
Replied by jltrussart11 on topic API: add_participants
Thanks for the reminder. Tparner code works like a charm!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose