Welcome to the LimeSurvey Community Forum

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

API: Invite participants to a survey

More
5 years 8 months ago #171451 by davebostockgmail
Replied by davebostockgmail on topic API: Invite participants to a survey
Hi Tony

I know this is a year old ... I have been trying this script as we now have a need to do this and it creates the entry into the token field but then refuses to send the email ... any thoughts?

Using 2.6.4 lts

Any hints or advice most welcome

Dave
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago #171465 by tpartner
Replied by tpartner on topic API: Invite participants to a survey
Can you send invitations through the LS GUI?

What is returned by $newMail?

If you see the error message, try replacing

Code:
echo 'Error - no invitation sent!';

with:

Code:
print_r($newMail);

or

Code:
echo $newMail;

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
5 years 8 months ago - 5 years 8 months ago #171480 by davebostockgmail
Replied by davebostockgmail on topic API: Invite participants to a survey
So I did that and this is what I get as an output

New token created in survey 146297:
TID - 23
Token - B4ULIxdu2CpvDi7
Array ( [23] => Array ( [name] => Test Drive Customer
Last edit: 5 years 8 months ago by davebostockgmail.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago #171501 by tpartner
Replied by tpartner on 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
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago #171508 by DenisChenu
Replied by DenisChenu on 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 , plugin development .
I don't answer to private message.
The topic has been locked.
More
5 years 8 months ago #171516 by davebostockgmail
Replied by davebostockgmail on topic API: Invite participants to a survey
Thank you for your suggestion Denis

Unfortunately still not working.

Thanks
Dave
The topic has been locked.
More
5 years 8 months ago #171517 by davebostockgmail
Replied by davebostockgmail on 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
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago - 5 years 8 months ago #171537 by tpartner
Replied by tpartner on 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:

Code:
<?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:
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: 5 years 8 months ago by tpartner.
The topic has been locked.
More
5 years 6 months ago #173752 by solte98
Replied by solte98 on 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
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
3 weeks 17 hours ago #258245 by Mazi
Replied by Mazi on 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

 
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
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose