Add Limesurvey Participant using the API with a supplied custom token

Mehr
1 Monat 2 Wochen her #193928 von vikrantLumiq
I am currently using LimeSurvey v3.0.1 and want to add participants to a survey with a token as a parameter through LimeSurvey remote-control 2 API but LimeSurvey is generating a unique token itself every time the API is called.

Request: POST - http://<host>:<port>/index.php/admin/remotecontrol
Request payload:
{
"method": "add_participants",
"params": {
"sSessionKey": "my_session_key",
"iSurveyID": 12345,
"aParticipantData": [
{
"email": "Diese E-Mail-Adresse ist vor Spambots geschützt! Zur Anzeige muss JavaScript eingeschaltet sein!",
"lastname": " ",
"firstname": " ",
"language": "en",
"usesleft": 100,
"token": "customToken",
}
],
"bCreateToken": "false"
},
"id": 1
}



Response:
{
"id":1,
"result":[
{
"sent":"N",
"remindersent":"N",
"remindercount":0,
"completed":"N",
"usesleft":100,
"token":"QMnrKZoMoXnZNaz",
"email":"Diese E-Mail-Adresse ist vor Spambots geschützt! Zur Anzeige muss JavaScript eingeschaltet sein!",
"lastname":" ",
"firstname":" ",
"language":"en",
"emailstatus":"OK",
"tid":"38",
"participant_id":null,
"blacklisted":null,
"validfrom":null,
"validuntil":null,
"mpid":null
}
],
"error":null
}


Please tell me why this isn't working as expected or if there is somthing wrong with the Request Payload. Thanks!

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

LimeSurvey Partners
Mehr
1 Monat 2 Wochen her #193943 von tpartner
I'm not sure why you need to add "id" and maybe you should remove the quotes around "false" when defining the "bCreateToken" paramenter.

This simple PHP example works for me in version 3.22.0:

<?php
 
	require_once 'pathTo/jsonRPCClient.php';
 
	define( 'LS_BASEURL', 'http://pathTo/limesurvey/');
	define( 'LS_USER', 'admin' );
	define( 'LS_PASSWORD', 'password' );
 
	$iSurveyID = $_GET["sid"];
	$token = $_GET["token"];
	$email = $_GET["email"];
	$firstName =  $_GET["firstname"];
	$lastName = $_GET["lastname"];
	$language = $_GET["lang"];
 
	// 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 );
 
	// Check if token already exists
	$tokenExists = false;
	$aConditions = array("completed"=>"N");
	$listParticipants = $myJSONRPCClient->list_participants($sSessionKey, $iSurveyID, 0, 100000, false, false, $aConditions);
	foreach ($listParticipants as $value) {
		if(is_array($value)) {
			if(array_key_exists('token', $value)) {
				if($value['token'] == $token) {
					$tokenExists = true;
				}
			}
		}
	}
 
	// Token does not exist so we'll create one
	if($tokenExists == false) {
 
		// Define the token params
		$tokenParams = array("email"=>$email,"lastname"=>$lastName,"firstname"=>$firstName,"token"=>$token,"language"=>$language,"emailstatus"=>"OK");
		$aParticipantData=array($tokenParams);
		$bCreateToken = false;
 
		// Create the token in survey 2
		$newToken = $myJSONRPCClient->add_participants( $sSessionKey, $iSurveyID, $aParticipantData, $bCreateToken);
 
		// If token successfully created, redirect to survey
		if(isset($newToken[0]['tid']) && isset($newToken[0]['token'])) {
			echo('New token '.$newToken[0]['token'].', ID '.$newToken[0]['tid']);
		}
		// Otherwise, display errors
		else if (isset($newToken['status'])) {
			echo $newToken['status'];
		}
		else {
			echo '<br />';
			echo 'Error: '.$newToken[0]['errors']['token'][0];
		}
	}
	// Token already exists
	else {
		echo 'The token already exists!';
	}
 
	// 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.
Official LimeSurvey Partner - partnersurveys.com

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten

Abonnieren Sie unseren Newsletter

Abonnieren Sie unseren Newsletter für alle Neuigkeiten rund um LimeSurvey
captcha