Welcome to the LimeSurvey Community Forum

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

export_statistics stops working after participants take survey

More
2 years 4 months ago - 2 years 4 months ago #207549 by NoahMa
Hello,

i am trying to use the export_statistics api function in php.
if i use the function and pass the id of a survey that has no Responses(no one has taken the survey) then everything works as expected and i get a string wich i use to create a pdf file.
as soon as i try to do the same thing with a survey where there are responses i get the following error:
Code:
Fatal error: Uncaught Exception: Request error: attribute "Response_527793.527793X119X960962 is not defined. in C:\xampp\htdocs\JsonRPCClient.php:161 Stack trace: #0 C:\xampp\htdocs\auswertung.php(28): jsonRPCClient->__call('export_statisti...', Array) #1 {main} thrown in C:\xampp\htdocs\JsonRPCClient.php on line 161
LimeSurvey version: 4.3.23
Php version: 7.4.1

any ideas on what could cause this error would be greatly appreciated
thanks in advance N.M
Last edit: 2 years 4 months ago by NoahMa. Reason: added version numbers
The topic has been locked.
More
2 years 4 months ago #207578 by NoahMa
my code:
Code:
<?php
  include 'functions.php';
  define( 'LS_BASEURL', 'http://127.0.0.1/limesurvey-master');
  define( 'LS_USER', 'admin' );
  define( 'LS_PASSWORD', '******' );
  $myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' );
  $sSessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
 
  $sResult = $myJSONRPCClient-> export_statistics($sSessionKey,527793,"pdf");
  $sResult = base64_decode($sResult);
 
  file_put_contents("auswertung/survey.pdf", $sResult);
?>
The topic has been locked.
More
2 years 4 months ago #207580 by Joffm
Hi, Noah,

I used this code
Code:
...
require_once 'jsonrpcphp/JsonRPCClient.php';
 
define( 'LS_BASEURL', 'https://www.myServer.de/limesurvey');  // adjust this one to your actual LimeSurvey URL
define( 'LS_USER', 'myUser' );
define( 'LS_PASSWORD', 'myPassword' );
 
// the survey to process
$survey_id=886223;
// instantiate a new client
$myJSONRPCClient = new \org\jsonrpcphp\JsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' );
// receive session key
$sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
 
if(is_array($sessionKey))
{
    header("Content-type: application/json");
    echo json_encode($sessionKey);
    echo '<br />This is another test with sesssion key.<br />';
    die();
}
else if($sessionKey) // Is a valid session
{
/* Get the responses */
  $sResult = $myJSONRPCClient-> export_statistics($sessionKey,$survey_id,"pdf");
  $sResult = base64_decode($sResult);
 
  file_put_contents("survey.pdf", $sResult);
  }
 
 
  // Release the session key
  $myJSONRPCClient->release_session_key( $sSessionKey );
...

More or less the only difference is that there is a variable $survey_id.

And I get a nice pdf.


So I don't exactly know why your code throws an error.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: NoahMa
The topic has been locked.
More
2 years 4 months ago #207581 by NoahMa
Thank you for the quick reply,
I used your code and got the same error.
So I suspect there is something other than the code that's not working correctly
The topic has been locked.
More
2 years 4 months ago #207583 by Joffm
Did you check what this response 527793X119X960962 is?

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
More
2 years 4 months ago #207595 by NoahMa
im quite new to web development, how would i go about finding out what response 527793X119X960962 is?
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose