Remote Control 2 - Export_responses

More
4 years 8 months ago - 4 years 8 months ago #88249 by rbauling0818
rbauling0818 created the topic: Remote Control 2 - Export_responses
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: 4 years 8 months ago by rbauling0818. Reason: forgot a line of code to make it make sense

Please Log in to join the conversation.

More
4 years 8 months ago #88333 by rawson
rawson replied the topic: Remote Control 2 - Export_responses
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

Please Log in to join the conversation.

More
4 years 8 months ago #88338 by rbauling0818
rbauling0818 replied the topic: Remote Control 2 - Export_responses
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

Please Log in to join the conversation.

More
4 years 8 months ago #88341 by rawson
rawson replied the topic: Remote Control 2 - Export_responses
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.

Please Log in to join the conversation.

More
4 years 8 months ago #88348 by rbauling0818
rbauling0818 replied the topic: Remote Control 2 - Export_responses
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.

Please Log in to join the conversation.

More
4 years 8 months ago #88352 by rawson
rawson replied the topic: Remote Control 2 - Export_responses
Looks like a bug to me, you should put it into the bug tracker.
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

More
4 years 5 months ago #91700 by bebs
bebs replied the topic: Remote Control 2 - Export_responses
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 );
 
?>

Please Log in to join the conversation.

More
4 years 5 months ago #91846 by mdekker
mdekker replied the topic: Remote Control 2 - Export_responses
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 following user(s) said Thank You: bebs

Please Log in to join the conversation.

More
4 years 5 months ago #91855 by bebs
bebs replied the topic: Remote Control 2 - Export_responses

mdekker wrote: Try adding you survey language or null between 'csv' and 'all'


That was my problem, thanks very much!

Please Log in to join the conversation.

Did you already participate in our customer survey?

Don't miss your chance for great prices.

Please click here to participate:

Start now

Start now!

Just create your account and start using Limesurvey today.

Register now