- Posts: 62
- Thank you received: 3
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
RemoteControl 2 API, Export only a specified question group by token.
- Maverick87Shaka
- Topic Author
- Offline
- Senior Member
Less
More
7 years 7 months ago #140035
by Maverick87Shaka
RemoteControl 2 API, Export only a specified question group by token. was created by Maverick87Shaka
Hi,
in order to improve my application , I would like to retrieve the "response" array only of a specified question ID.
Actually I'm using the export_responses_by_token() function, that return all the responses.
looking at the documentation there is a $aFields ( array ) named as "Optional Selected fields", it's this what I need?
How I have to build this array?
The group that I need actually is "personal data" (GroupID 121), containing question code ANAG1,ANAG2 and so on.
My actual code is:
And return all the response without any filter.
Thanks
in order to improve my application , I would like to retrieve the "response" array only of a specified question ID.
Actually I'm using the export_responses_by_token() function, that return all the responses.
looking at the documentation there is a $aFields ( array ) named as "Optional Selected fields", it's this what I need?
How I have to build this array?
The group that I need actually is "personal data" (GroupID 121), containing question code ANAG1,ANAG2 and so on.
My actual code is:
Code:
$myJSONRPCClient->export_responses_by_token($sSessionKey,$iSurveyID,$sDocumentType,$sToken,$sLanguageCode,$sCompletionStatus,$sHeadingType,$sResponseType);
Thanks
The topic has been locked.
- teracomp
- Offline
- Elite Member
Less
More
- Posts: 162
- Thank you received: 14
7 years 4 months ago #144363
by teracomp
Dave Phillips
Replied by teracomp on topic RemoteControl 2 API, Export only a specified question group by token.
I just started looking at the API and found the aFields is perfect for my needs. In this particular survey, I have equation questions that score questions based on my algorithm and store the response accordingly. Using the API, I retrieve the computed results:
The only issue I'm having is the $iFromResponseID and $iToResponseID don't actually filter the results...I get all of the completed surveys.
At any rate, just include the SQGA fields in an array and you should be able to get a nice concise report.
Code:
$sDocumentType = 'json'; //pdf, csv, xls, doc, json $sLanguageCode = 'en'; $sCompletionStatus = 'complete'; // 'incomplete' or 'all' -- default: 'all' $sHeadingType = 'code'; // 'full' or 'abbreviated' -- default: 'code' $sResponseType = 'short'; // or 'long' -- default: 'short' $iFromResponseID = 10; $iToResponseID = 18; //(see get_response_ids() for range of possible ids) $aFields = array( 'id', '171768X29X1042','submitdate', '171768X7X42', '171768X7X44', '171768X7X45', '171768X7X1257', '171768X7X1258', '171768X7X1259', '171768X7X1260', '171768X7X1261', '171768X7X1262' ); $responses = $myJSONRPCClient->export_responses( $sSessionKey, $sid, $sDocumentType, $sLanguageCode, $sCompletionStatus, $sHeadingType, $sResponseType, $iFromResponseID, $iToResponseId, $aFields); // convert and echo to screen to review $strDecoded = base64_decode( $responses ); $res_json = json_decode($strDecoded); echo '<pre>'; print_r($res_json); echo '</pre>';
At any rate, just include the SQGA fields in an array and you should be able to get a nice concise report.
Dave Phillips
The topic has been locked.
- teracomp
- Offline
- Elite Member
Less
More
- Posts: 162
- Thank you received: 14
7 years 4 months ago #144364
by teracomp
Dave Phillips
Replied by teracomp on topic RemoteControl 2 API, Export only a specified question group by token.
Another solution is to connect to your server and get the responses you want directly. Since i already know the SGQA codes I want, this is much more efficient:
Assuming you can connect to your MySql database on your server (e.g., require_once 'server_connection.php' ), this is VERY fast. Of course you miss out on some of the cool features of the API, but if you know specifically what you want, just go get it directly!
Code:
$fields = "71768X7X42 AS C1A, 71768X7X44 AS C1B, 71768X7X45 AS C1C, 71768X7X1257 AS C2A, 71768X7X1258 AS C2B, 71768X7X1259 AS C2C, 71768X7X1260 AS C3A, 71768X7X1261 AS C3B, 71768X7X1262 AS C3C"; $sql = "SELECT $fields FROM lime_survey_71768 WHERE id=14"; $result = $mysqli->query($sql) or $myError = $mysqli->error.__LINE__; if ( $result->num_rows > 0 ) { $row = $result->fetch_assoc(); echo '<pre>'; print_r($row); echo '</pre>'; } else { echo '<em>Error</em>'; }
Dave Phillips
The topic has been locked.