- Posts: 3
- Thank you received: 0
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
- Topic Author
- Offline
- New Member
Less
More
10 years 8 months ago #98093
by hstrhtrh
when trying to create new token I get "Invalid session key" was created by hstrhtrh
I am getting a session key.
Here is an example of my code.
The output is:
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:
The topic has been locked.
- mdekker
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 55
- Thank you received: 12
10 years 8 months ago #98097
by mdekker
---
Menno Dekker
Replied by mdekker on topic when trying to create new token I get "Invalid session key"
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
10 years 8 months ago #98102
by hstrhtrh
Replied by hstrhtrh on topic when trying to create new token I get "Invalid session key"
Ok,
That worked, for creating a token. However, it is just generating a random token and only returning
without the token ID. I would like to be able to create a token is this possible?
That worked, for creating a token. However, it is just generating a random token and only returning
Code:
Array ( [firstname] => [lastname] => [token] => )
The topic has been locked.
- hstrhtrh
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
10 years 8 months ago - 10 years 8 months ago #98104
by hstrhtrh
Finally got it working!
Thanks
Replied by hstrhtrh on topic when trying to create new token I get "Invalid session key"
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.