{"id":14,"date":"2026-11-18T20:44:22","date_gmt":"2026-11-18T20:44:22","guid":{"rendered":"https:\/\/joshjh.tech\/?p=14"},"modified":"2026-11-18T20:47:35","modified_gmt":"2026-11-18T20:47:35","slug":"limesurvey-api-client-data-warehouse-sync","status":"publish","type":"post","link":"https:\/\/joshjh.tech\/?p=14","title":{"rendered":"Building a LimeSurvey API Client and Data Warehouse Sync"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Building a LimeSurvey API Client and Data Warehouse Sync<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Survey data becomes far more useful when teams can retrieve it consistently, inspect its structure, and analyze responses alongside other information. This development effort delivers a Java client and command-line interface for LimeSurvey\u2019s RemoteControl API, then adds a repeatable synchronization path that loads survey metadata and response rows into a PostgreSQL data warehouse.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The implementation is organized around two jobs: make the RemoteControl endpoints straightforward and safe to call, and transform their results into a relational snapshot that can be queried downstream.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Calling LimeSurvey RemoteControl endpoints<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">LimeSurvey RemoteControl uses JSON-RPC over HTTP POST, including for read-only operations. The client sends requests to the configured RemoteControl URL with a method name, positional <code>params<\/code> array, and incrementing request ID. It authenticates first with <code>get_session_key<\/code>; the resulting key is prepended to every subsequent method\u2019s parameters. When the client closes, it calls <code>release_session_key<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A typical request is shaped like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  &quot;method&quot;: &quot;list_questions&quot;,\n  &quot;params&quot;: [&quot;&lt;session-key&gt;&quot;, 12345, null, null],\n  &quot;id&quot;: 7\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The Java implementation wraps that protocol in named methods, so callers do not need to assemble JSON-RPC requests themselves. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>try (LimeSurveyClient client = LimeSurveyClient.connect(\n        URI.create(System.getenv(&quot;LIMESURVEY_URL&quot;)),\n        System.getenv(&quot;LIMESURVEY_USERNAME&quot;),\n        System.getenv(&quot;LIMESURVEY_PASSWORD&quot;))) {\n    JsonNode surveys = client.listSurveys(null, null);\n    JsonNode questions = client.listQuestions(12345, null, null);\n    byte[] export = client.exportResponses(12345, &quot;json&quot;, new ExportOptions());\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Try-with-resources makes session cleanup part of the call lifecycle. Optional parameters are passed as <code>null<\/code> when the caller wants LimeSurvey\u2019s defaults. The library exposes these retrieval methods:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>list_surveys<\/code> for surveys visible to the account, with optional user and survey-group filters.<\/li>\n\n\n<li><code>get_survey_properties<\/code> and <code>get_language_properties<\/code> for survey configuration.<\/li>\n\n\n<li><code>get_fieldmap<\/code> for the export fields available for a survey.<\/li>\n\n\n<li><code>list_groups<\/code> and <code>get_group_properties<\/code> for question-group structure and details.<\/li>\n\n\n<li><code>list_questions<\/code> and <code>get_question_properties<\/code> for question records and details.<\/li>\n\n\n<li><code>get_summary<\/code> for survey statistics.<\/li>\n\n\n<li><code>get_response_ids<\/code> to retrieve response IDs associated with a participant token.<\/li>\n\n\n<li><code>export_responses<\/code> and <code>export_responses_by_token<\/code> for response data, with export options such as format, language, completion status, heading type, response type, selected fields, and response-ID bounds where supported.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Export calls return base64-encoded content from the API; the client decodes it to bytes so JSON, CSV, and other supported formats are not corrupted. Token-specific calls require a token supplied through the environment rather than a command-line argument.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Reliable endpoint integration needs more than sending a request. The client checks HTTP status, parses JSON, verifies the response ID, surfaces JSON-RPC and LimeSurvey status errors, and rejects absent or malformed results. Export payloads are validated before decoding. Error messages redact session keys, credentials, and participant tokens. It deliberately avoids silent retries or automatic re-authentication, making failures visible to the caller.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">From API responses to a warehouse model<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>sync<\/code> command composes the endpoints into a survey-by-survey extraction. It lists accessible surveys, reads each survey\u2019s properties, groups and questions, and retrieves a JSON response export. It then maps response export columns back to question records using question codes, including sub-question codes such as <code>Q002_SQ001<\/code> and <code>Q002[SQ001]<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The PostgreSQL data warehouse is organized as a dedicated schema with these core tables:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>survey<\/code> stores identifiers, title, active state, dates, group, language, and the last synchronization run.<\/li>\n\n\n<li><code>question_group<\/code> and <code>question<\/code> hold the survey structure, including parent\/child question relationships and ordering.<\/li>\n\n\n<li><code>response<\/code> stores one row per response, selected response metadata, completion state, and a filtered JSONB representation of the export.<\/li>\n\n\n<li><code>answer<\/code> stores non-empty answer values by response and export field code, with a question link when the code can be resolved.<\/li>\n\n\n<li><code>sync_run<\/code> records the run status, survey counts, timestamps, and a bounded error summary.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Each survey is handled as a transaction. The sync process upserts its survey row, replaces its existing groups, questions, responses, and answers, and commits the snapshot together. If one survey fails, its transaction rolls back while the remaining surveys continue. This makes reruns idempotent and removes rows for responses that have since been deleted in LimeSurvey. The warehouse holds current state rather than a full history; <code>sync_run<\/code> provides operational run records.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">LimeSurvey\u2019s <code>ERR_NO_DATA<\/code> and <code>ERR_NO_RESPONSE_TABLE<\/code> responses are treated as empty lists or exports where appropriate, allowing inactive or unanswered surveys to be represented with their metadata and questions. Other errors are recorded as failures. At completion, the run is marked <code>success<\/code>, <code>partial<\/code>, or <code>failed<\/code>, and an incomplete sync exits with a nonzero status.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Privacy is built into the transformation. Participant tokens, IP addresses, and referrer URLs are removed before response data is written to either the <code>answer<\/code> rows or the JSONB <code>raw<\/code> field. Response answers may still contain sensitive information, so warehouse access and retention should be managed accordingly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Running the client and synchronization<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The project is packaged with Maven as an executable JAR. Configure the LimeSurvey endpoint and account through environment variables; supply the password via the environment or the client\u2019s no-echo terminal prompt. For network connections beyond a trusted local environment, use HTTPS.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The CLI has commands for each supported retrieval operation, such as <code>list-surveys<\/code>, <code>survey-properties<\/code>, <code>list-questions<\/code>, <code>summary<\/code>, <code>response-ids<\/code>, and the two response export variants. The warehouse sync is invoked separately:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export LIMESURVEY_URL=&#039;https:\/\/surveys.example.org\/index.php\/admin\/remotecontrol&#039;\nexport LIMESURVEY_USERNAME=&#039;your-username&#039;\nexport LIMESURVEY_PASSWORD=&#039;your-password&#039;\nexport PG_URL=&#039;jdbc:postgresql:\/\/localhost:5432\/analytics&#039;\nexport PG_USER=&#039;warehouse-user&#039;\n# Set PG_PASSWORD securely, or enter it at the terminal prompt.\n\njava -jar target\/limesurvey-client-1.0.0.jar sync<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The database connection URL must not embed credentials. The sync installs its idempotent schema definition in the dedicated namespace and uses prepared statements for database writes. Its database role therefore needs permission to create that schema and its tables, while all synchronized objects remain isolated from LimeSurvey\u2019s own application tables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A foundation for analysis<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This work turns a collection of API calls into a reusable integration layer: the Java client handles session and protocol details, the CLI makes retrieval and synchronization operational, and the warehouse model preserves survey structure alongside response-level and answer-level data. Because question mapping, error reporting, transactional replacement, and privacy filtering are handled in the pipeline, analysts can query consistent relational rows without having to reconstruct every LimeSurvey export by hand.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Survey data becomes far more useful when teams can retrieve it consistently, inspect its structure, and analyze responses alongside other information. This development effort delivers a Java client and command-line interface for LimeSurvey\u2019s RemoteControl API, then adds a repeatable synchronization path that loads survey metadata and response rows into a PostgreSQL data warehouse.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-14","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/joshjh.tech\/index.php?rest_route=\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/joshjh.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joshjh.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joshjh.tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joshjh.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14"}],"version-history":[{"count":1,"href":"https:\/\/joshjh.tech\/index.php?rest_route=\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":16,"href":"https:\/\/joshjh.tech\/index.php?rest_route=\/wp\/v2\/posts\/14\/revisions\/16"}],"wp:attachment":[{"href":"https:\/\/joshjh.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joshjh.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joshjh.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}