Welcome, Guest
Username: Password: Remember me

TOPIC: Remote Control 2 - Export_responses

Remote Control 2 - Export_responses 1 year 10 months ago #88249

Hello,

I'm using LimeSurvey Version 2.00+ Build 121115 and I'm trying to get the export_responses function to work, but I keep getting an error. It may be an error on my part, but I'm not sure.

Here's my code
require_once 'jsonRPCClient.php';
 
define( 'LS_BASEURL', 'limesurveyurl');
define( 'LS_USER', 'admin' );
define( 'LS_PASSWORD','password' )
 
$survey_id=96293;
$sSurveyLanguage = 'en';
$status = 'all';
$heading = 'code';
$responseType = 'short';
$doc_type= 'csv';
 
$myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/admin/remotecontrol' );
$sSessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
 
$export_responses = $myJSONRPCClient->export_responses($sSessionKey, $survey_id, $doc_type, $sSurveyLanguage, $status, $heading, $responseType);
 

I keep getting this error when I get it to work: [status] => Error: No Permission or I get an error thrown form the jsonRPCClient file.

Does anyone have any insight into this?
Last Edit: 1 year 10 months ago by rbauling0818. Reason: forgot a line of code to make it make sense
The administrator has disabled public write access.

Re: Remote Control 2 - Export_responses 1 year 10 months ago #88333

  • rawson
  • rawson's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Thank you received: 1
  • Karma: 1
I tried this and also got an error, is this the same error that you're getting?
Fatal error: Uncaught exception 'Exception' with message 'Request error: CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' in jsonrpcphp\jsonRPCClient.php on line 155 Exception: Request error: CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'return ORDER BY `lime_survey_854479`.`id` LIMIT 1' at line 4 in jsonrpcphp\jsonRPCClient.php on line 155
The administrator has disabled public write access.

Re: Remote Control 2 - Export_responses 1 year 10 months ago #88338

I did get that error initially, but when I upgraded it was fixed in one of the bugs. Still doesn't seem to make it work though. I keep getting this error:
Exception: Incorrect response id (request id: 1, response id: )

Here's the bug in case you're wondering:
Export Responses Bug
The administrator has disabled public write access.

Re: Remote Control 2 - Export_responses 1 year 10 months ago #88341

  • rawson
  • rawson's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Thank you received: 1
  • Karma: 1
After updating I started getting the same error, until I went to my limesurvey admin page which prompted me to update the database. After clicking on the button to update the database I now get the following error:
Request error: unknown method or incorrect parameters

I will try fiddling with the parameters to see if I can get it to work.
The administrator has disabled public write access.

Re: Remote Control 2 - Export_responses 1 year 10 months ago #88348

Hmm I got that error too depending on what you put into the $doc_type variable the error changes and if you take out the survey id it won't give you the php error it'll return
Array{[status] => No Permission]}

I never got it to work tried all day yesterday.
The administrator has disabled public write access.

Re: Remote Control 2 - Export_responses 1 year 10 months ago #88352

  • rawson
  • rawson's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Thank you received: 1
  • Karma: 1
Looks like a bug to me, you should put it into the bug tracker.
The administrator has disabled public write access.
The following user(s) said Thank You: DenisChenu

Re: Remote Control 2 - Export_responses 1 year 7 months ago #91700

  • bebs
  • bebs's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 48
  • Thank you received: 2
  • Karma: 0
Hello.

fyi the code below works fine to me (v20130118) and forces the download of a csv file that contains the answer metadata ("id","Completed","Last page","Start language","Date started","Date last action","IP address","Referring URL").

thank you devs.

Unfortunately (to me) I'm looking for a way to export all the answers for a given survey and answer "id" remotely. Is there any possibility yet?

Thanks. B.
<?php
require_once 'includes/jsonRPCClient.php';
 
define( 'LS_BASEURL', 'http://limesurvey.localhost/index.php');  // adjust this one to your actual LimeSurvey URL
define( 'LS_USER', 'rpcuser' );
define( 'LS_PASSWORD', 'rpcpass' );
 
// the survey to process
$survey_id=326549;
 
// instanciate a new client 
$myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/admin/remotecontrol' );
 
// receive session key
$sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
 
//export answers
$responses = $myJSONRPCClient->export_responses( $sessionKey, $survey_id, 'csv', 'all', 'code', 'long');
header('Content-Disposition: attachment;filename="answers_data.csv"');
header('Content-Type: application/force-download'); 
print_r(base64_decode($responses), null);
 
// release the session key
$myJSONRPCClient->release_session_key( $sessionKey );
 
?>
The administrator has disabled public write access.

Re: Remote Control 2 - Export_responses 1 year 7 months ago #91846

  • mdekker
  • mdekker's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 341
  • Thank you received: 68
  • Karma: 38
Try adding you survey language or null between 'csv' and 'all'

This is the signature:

/**
* RPC Routine to export responses.
* Returns the requested file as base64 encoded string
*
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iSurveyID Id of the Survey
* @param string $sDocumentType pdf,csv,xls,doc
* @param string $sLanguageCode The language to be used
* @param string $sCompletionStatus Optional 'complete','incomplete' or 'all' - defaults to 'all'
* @param string $sHeadingType 'code','full' or 'abbreviated' Optional defaults to 'code'
* @param string $sResponseType 'short' or 'long' Optional defaults to 'short'
* @param integer $iFromResponseID Optional
* @param integer $iToResponseID Optional
* @param array $aFields Optional Selected fields
* @return array|string On success: Requested file as base 64-encoded string. On failure array with error information
* */
public function export_responses($sSessionKey, $iSurveyID, $sDocumentType, $sLanguageCode=null, $sCompletionStatus='all', $sHeadingType='full', $sResponseType='short', $iFromResponseID=null, $iToResponseID=null, $aFields=null)
---
Menno Dekker
The administrator has disabled public write access.
The following user(s) said Thank You: bebs

Re: Remote Control 2 - Export_responses 1 year 7 months ago #91855

  • bebs
  • bebs's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 48
  • Thank you received: 2
  • Karma: 0
mdekker wrote:
Try adding you survey language or null between 'csv' and 'all'

That was my problem, thanks very much!
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.442 seconds
Donation Image