API: Invite participants to a survey

More
11 months 3 weeks ago #171501 by tpartner
Sorry Dave, I don't know why that's not working. I resurrected an old 2.6.4 version and I get the same result. Maybe a bug in that version?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
The following user(s) said Thank You: davebostockgmail

Please Log in or Create an account to join the conversation.

More
11 months 3 weeks ago #171508 by DenisChenu
Maybe you can try to replace github.com/LimeSurvey/LimeSurvey/blob/2....tecontrol_handle.php

(keep same major version)

Without any warantee ;)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand .
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

More
11 months 3 weeks ago #171516 by davebostockgmail
Thank you for your suggestion Denis

Unfortunately still not working.

Thanks
Dave

Please Log in or Create an account to join the conversation.

More
11 months 3 weeks ago #171517 by davebostockgmail
Thanks for trying ... I will install a 3.xxx version and try with that ... we need to upgrade anyway ... so I guess this forces our hand.

Will this script work for a 3.xxx version?

Cheers
Dave

Please Log in or Create an account to join the conversation.

More
11 months 3 weeks ago - 11 months 3 weeks ago #171537 by tpartner
Using version 3.13.2, this will create a token defined by $token and send the invitation to that token:

<?php
 
	define( 'LS_BASEURL', 'http://pathTo/limesurvey/');
	define( 'LS_USER', 'admin' );
	define( 'LS_PASSWORD', '****' );
 
	require_once 'relativePathTo/application/libraries/jsonRPCClient.php';
 
	$iSurveyID = 885886;
	$token = 'ABCDE';
	$email = 'example@example.com';
	$LastNameAPI = 'Firstname' ;
	$FirstNameAPI = 'Lastname' ;
 
 
	// 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"=>$email,"lastname"=>$LastNameAPI,"firstname"=>$FirstNameAPI,"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 '<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 );
?>

If you want to generate a random token value instead of defining it, change this:
$bCreateToken = false;

To this:
$bCreateToken = true;

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 11 months 3 weeks ago by tpartner.

Please Log in or Create an account to join the conversation.

More
10 months 5 days ago #173752 by solte98
So is this a bug in 2.6.4 as the invite_participants is not working in that version it seems

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!