Hi guys,
We're trying to write a code for exporting responses as CSV format, by using API.
Please see the code which we created below:
<?php
/* * * * * * * * * * * * * * * * * * * * * *
* Start Edit
* * * * * * * * * * * * * * * * * * * * * */
define( 'LS_BASEURL', '
example.com
' ); // if subbfolder => https://localhost/MyFolder
define( 'LS_USER', '***' );
define( 'LS_PASSWORD', '***’);
$iSurveyId = 170925; // survey ID
/* * * * * * * * * * * * * * * * * * * * * *
* End Edit
* * * * * * * * * * * * * * * * * * * * * */
/* using LimeSurvey (LS) RemoteControly API version 2's JSON-RPC method */
include "application/libraries/jsonRPCClient.php";
/* instantiate a new client */
$lsJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' );
/* receive session key */
$sessionKey = $lsJSONRPCClient->export_responses(LS_USER, LS_PASSWORD);
//export answers
$responses = $lsJSONRPCClient->call('export_responses', array( $sessionKey, '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 */
$lsJSONRPCClient->release_session_key($sessionKey);
?>
We get this error:
[01-Dec-2017 14:26:02 Etc/GMT] PHP Warning: base64_decode() expects parameter 1 to be string, array given in /home/resea2ig/public_html/lime/youla/ex.php on line 32
[01-Dec-2017 14:26:02 Etc/GMT] PHP Stack trace:
[01-Dec-2017 14:26:02 Etc/GMT] PHP 1. {main}() /home/resea2ig/public_html/lime/youla/ex.php:0
[01-Dec-2017 14:26:02 Etc/GMT] PHP 2. base64_decode() /home/resea2ig/public_html/lime/youla/ex.php:32
When I open downloaded file, it says “Array( [status] => Invalid session key)”
I'm just wondering if you anyone managed to create a code or can help us to solve the issue.
Many thanks
Mehdi