Welcome to the LimeSurvey Community Forum

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

API: add_participants

More
9 years 6 months ago #149674 by Dongebtris_52670
]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', '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); ?>
The topic has been locked.
More
9 years 6 months 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', '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 ); ?>

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: Dongebtris_52670
The topic has been locked.
More
9 years 6 months ago #149685 by Dongebtris_52670
Thanks a lot i get it to works with you precious help!

have a nice day!
The topic has been locked.
More
9 years 5 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
survey-consulting.com
offlinesurveys.com
Feel free to contact me by email for professional LimeSurvey support!
The topic has been locked.
More
9 years 5 months ago #152317 by Dongebtris_52670
Thanks for the reminder. Tparner code works like a charm!
The topic has been locked.
Moderators: tpartner, holch

Lime-years ahead

Online-surveys for every purse and purpose