Welcome, Guest
Username: Password: Remember me

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

when trying to create new token I get "Invalid session key" 1 year 1 week ago #98093

  • hstrhtrh
  • hstrhtrh's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 3
  • Karma: 0
I am getting a session key.

Here is an example of my 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:
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 administrator has disabled public write access.

when trying to create new token I get "Invalid session key" 1 year 1 week ago #98097

  • mdekker
  • mdekker's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 341
  • Thank you received: 68
  • Karma: 38
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 administrator has disabled public write access.

when trying to create new token I get "Invalid session key" 1 year 1 week ago #98102

  • hstrhtrh
  • hstrhtrh's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 3
  • Karma: 0
Ok,

That worked, for creating a token. However, it is just generating a random token and only returning
Array
(
    [firstname] => 
    [lastname] => 
    [token] => 
)
without the token ID. I would like to be able to create a token is this possible?
The administrator has disabled public write access.

when trying to create new token I get "Invalid session key" 1 year 1 week ago #98104

  • hstrhtrh
  • hstrhtrh's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 3
  • Karma: 0
<?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: 1 year 1 week ago by hstrhtrh. Reason: chaned topic icon
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.335 seconds
Donation Image