API: Invite participants to a survey

More
2 months 3 weeks ago #171501 by tpartner
tpartner replied the topic: API: Invite participants to a survey
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.
The following user(s) said Thank You: davebostockgmail

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

More
2 months 3 weeks ago #171508 by DenisChenu
DenisChenu replied the topic: API: Invite participants to a survey
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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

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

More
2 months 3 weeks ago #171516 by davebostockgmail
davebostockgmail replied the topic: API: Invite participants to a survey
Thank you for your suggestion Denis

Unfortunately still not working.

Thanks
Dave

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

More
2 months 3 weeks ago #171517 by davebostockgmail
davebostockgmail replied the topic: API: Invite participants to a survey
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
2 months 3 weeks ago - 2 months 3 weeks ago #171537 by tpartner
tpartner replied the topic: API: Invite participants to a survey
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.
Last Edit: 2 months 3 weeks ago by tpartner.

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

More
1 month 4 days ago #173752 by solte98
solte98 replied the topic: API: Invite participants to a survey
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!