Welcome to the LimeSurvey Community Forum

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

when trying to create new token I get "Invalid session key"

  • hstrhtrh
  • hstrhtrh's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 8 months ago #98093 by hstrhtrh
I am getting a session key.

Here is an example of my code.

Code:
 
//require_once 'jsonRPCClient.php';
require_once '/var/www/sites/site/survey/application/libraries/jsonRPCClient.php';
$rt = new jsonRPCClient('https://site/survey/admin/remotecontrol');
 
    $sSessionKey= $rt->call('get_session_key', array('user','pass'));
 
        if (is_array($sSessionKey)) {echo $sSessionKey['status']; die();}
        else
        {
            echo 'Retrieved session key'.'<br>';
        }
 
$sessionkey = $sSessionKey;
// performs some basic operation
 
$rtdata["id"] = 1;
$rtdata["params"]["sessionkey"] = $sessionkey;
$rtdata["params"]["surveyID"] = "17164";
$rtdata["params"]["participantData"]["firstname"] = "Test";
$rtdata["params"]["participantData"]["token"] = "tom-1";
$rtdata["params"]["createTokenKey"] = 1;
//printf("<pre>");
 
//printf(json_encode($rtdata));
printf("<pre>");
print_r($rtdata);
printf("</pre>");
$encodedjson = json_encode($rtdata);
 
 
try {
//print_r($rtdata);
//printf("</pre>");
 
        if($output = $rt->call('add_participants', $rtdata))
        {
           printf("<pre>");
           print_r($output);
           printf("</pre>");
 
        }
        echo "Attempting to add token";
 
} catch (Exception $e) {
        echo nl2br($e->getMessage()).'<br />'."\n";
}
 

The output is:
Code:
Retrieved session key
 
Array
(
    [id] => 1
    [params] => Array
        (
            [sessionkey] => 4su92x332t74eg2uc4gkhr8yqx2t2aw9
            [surveyID] => 17164
            [participantData] => Array
                (
                    [firstname] => Test
                    [token] => tom-1
                )
 
            [createTokenKey] => 1
        )
 
)
 
Array
(
    [status] => Invalid session key
)
 
Attempting to add token
 
The topic has been locked.
  • mdekker
  • mdekker's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 8 months ago #98097 by mdekker
I think you should not pass the $rtdata but just the params element inside it. Just like the way you retrieve the sessionkey.

---
Menno Dekker
The topic has been locked.
  • hstrhtrh
  • hstrhtrh's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 8 months ago #98102 by hstrhtrh
Ok,

That worked, for creating a token. However, it is just generating a random token and only returning
Code:
Array
(
    [firstname] => 
    [lastname] => 
    [token] => 
)
without the token ID. I would like to be able to create a token is this possible?
The topic has been locked.
  • hstrhtrh
  • hstrhtrh's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 8 months ago - 10 years 8 months ago #98104 by hstrhtrh
Code:
<?php
 
$rt = new jsonRPCClient('https://site/survey/admin/remotecontrol');
 
    $sSessionKey= $rt->get_session_key('user','password');
 
 
        if (is_array($sSessionKey)) {echo $sSessionKey['status']; die();}
        else
        {
            echo 'Retrieved session key'.'<br>';
        }
 
$sessionkey = $sSessionKey;
// performs some basic operation
 
$data[1]["token"] = $_POST["ticketid"];
 
 
$rtdata["params"]["sessionkey"] = $sessionkey;
$rtdata["params"]["surveyID"] = "17164";
 
try {
 
        if($output = $rt->add_participants($rtdata["params"]["sessionkey"], $rtdata["params"]["surveyID"], $data, false))
        {
           printf("<pre>");
           print_r($output);
           printf("</pre>");
 
        }
 
} catch (Exception $e) {
  echo nl2br($e->getMessage()).'<br />'."\n";
}
 
$rt->release_session_key($sessionkey);
 
?>
 
 

Finally got it working!

Thanks
Last edit: 10 years 8 months ago by hstrhtrh. Reason: chaned topic icon
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose