Welcome to the LimeSurvey Community Forum

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

API: Invite participants to a survey

More
7 years 1 month 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.
The following user(s) said Thank You: davebostockgmail
The topic has been locked.
More
7 years 1 month 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 support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
More
7 years 1 month ago #171516 by davebostockgmail
Thank you for your suggestion Denis

Unfortunately still not working.

Thanks
Dave
The topic has been locked.
More
7 years 1 month 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
The topic has been locked.
More
7 years 1 month ago - 7 years 1 month ago #171537 by tpartner
Using version 3.13.2, this will create a token defined by $token and send the invitation to that token:

Code:
<?php
 
  define( 'LS_BASEURL', 'https://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:
Code:
$bCreateToken = false;

To this:
Code:
$bCreateToken = true;

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 1 month ago by tpartner.
The topic has been locked.
More
6 years 11 months 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
The topic has been locked.
More
1 year 5 months ago #258245 by Mazi

So is this a bug in 2.6.4 as the invite_participants is not working in that version it seems

 
We are using that API function regularly. It must have been a temporary issue. I just tested that function at the latest 6.x version and it is working fine there.
A better approach for fully automating invitation sending is using a cronjob script .

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.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose