LimeSurvey RemoteControl 2 API
Automate LimeSurvey survey management via the RemoteControl 2 JSON-RPC API.
Prerequisites
Required Environment Variables:
- -
LIMESURVEY_URL — Full URL to RemoteControl endpoint (e.g., https://survey.example.com/index.php/admin/remotecontrol) - INLINECODE2 — Service account username
- INLINECODE3 — Service account password
Security Recommendations:
- 1. Use a least-privilege service account, not your full admin credentials
- Create a dedicated LimeSurvey user with minimal required permissions (survey management only, no system administration)
- Use a strong, unique password; rotate periodically after initial use
- Never commit credentials to version control — use environment variables or secure vaults only
- Verify the RemoteControl API is accessible only from trusted networks
Setup:
CODEBLOCK0
Quick Start
Setup
Set environment variables:
CODEBLOCK1
CLI Usage
CODEBLOCK2
Python API Usage
CODEBLOCK3
Common Workflows
Survey Management
List all surveys:
CODEBLOCK4
Activate a survey:
CODEBLOCK5
Get survey statistics:
CODEBLOCK6
Copy a survey:
CODEBLOCK7
Participant Management
Initialize participant table:
CODEBLOCK8
Add participants:
CODEBLOCK9
Send invitations:
CODEBLOCK10
List participants with filters:
CODEBLOCK11
Response Operations
Export all responses:
CODEBLOCK12
Export only completed responses:
CODEBLOCK13
Export by token:
CODEBLOCK14
Add a response programmatically:
CODEBLOCK15
Question & Group Operations
List groups:
CODEBLOCK16
Add a question group:
CODEBLOCK17
List questions:
CODEBLOCK18
Get question details:
CODEBLOCK19
Export & Reporting
Generate statistics PDF:
CODEBLOCK20
Get submission timeline:
CODEBLOCK21
Get survey fieldmap:
CODEBLOCK22
Error Handling
All API functions return status objects on error:
CODEBLOCK23
Use try/except for connection errors:
CODEBLOCK24
Reference Documentation
- - API Reference - Complete function reference with parameters and return values
- Examples - Practical code examples for common tasks
Available Functions
Session
- -
get_session_key(username, password) - Create session - INLINECODE5 - Close session
Surveys
- -
list_surveys(session_key) - List all surveys - INLINECODE7 - Get properties
- INLINECODE8 - Update properties
- INLINECODE9 - Activate survey
- INLINECODE10 - Delete survey
- INLINECODE11 - Duplicate survey
- INLINECODE12 - Import from file
- INLINECODE13 - Get statistics
Participants
- -
activate_tokens(session_key, survey_id, attributes) - Initialize table - INLINECODE15 - List participants
- INLINECODE16 - Add participants
- INLINECODE17 - Delete participants
- INLINECODE18 - Get properties
- INLINECODE19 - Update properties
- INLINECODE20 - Send invitations
- INLINECODE21 - Send reminders
Responses
- -
export_responses(session_key, survey_id, format, ...) - Export responses - INLINECODE23 - Export by token
- INLINECODE24 - Add response
- INLINECODE25 - Update response
- INLINECODE26 - Delete response
- INLINECODE27 - Find response IDs
Questions & Groups
- -
list_groups(session_key, survey_id) - List groups - INLINECODE29 - Create group
- INLINECODE30 - Delete group
- INLINECODE31 - Get properties
- INLINECODE32 - Update properties
- INLINECODE33 - List questions
- INLINECODE34 - Get properties
- INLINECODE35 - Update properties
- INLINECODE36 - Import question
- INLINECODE37 - Delete question
Export & Reporting
- -
export_statistics(session_key, survey_id, doc_type, language, graph) - Export statistics - INLINECODE39 - Submission timeline
- INLINECODE40 - Get question codes
Notes
- - Session management: Always close sessions with
release_session_key or use LimeSurveySession context manager - Base64 encoding: Export functions return base64-encoded data — use
client.decode_base64() or INLINECODE44 - Permissions: API calls respect user permissions — same as logging into admin interface
- Rate limiting: LimeSurvey has brute-force protection on authentication
- JSON-RPC: Content-Type must be
application/json (handled automatically by client)
Full API Documentation
Official LimeSurvey API: https://api.limesurvey.org/classes/remotecontrol-handle.html
Manual: https://www.limesurvey.org/manual/RemoteControl2API
LimeSurvey RemoteControl 2 API
通过 RemoteControl 2 JSON-RPC API 自动化 LimeSurvey 调查管理。
前提条件
必需的环境变量:
- - LIMESURVEYURL — RemoteControl 端点的完整 URL(例如 https://survey.example.com/index.php/admin/remotecontrol)
- LIMESURVEYUSER — 服务账户用户名
- LIMESURVEY_PASSWORD — 服务账户密码
安全建议:
- 1. 使用最小权限服务账户,而非完整管理员凭据
- 创建具有最小必要权限的专用 LimeSurvey 用户(仅限调查管理,无系统管理权限)
- 使用强且唯一的密码;初始使用后定期轮换
- 切勿将凭据提交到版本控制——仅使用环境变量或安全保管库
- 确保 RemoteControl API 仅可从受信任网络访问
设置:
bash
export LIMESURVEY_URL=https://survey.example.com/index.php/admin/remotecontrol
export LIMESURVEYUSER=serviceaccount_username
export LIMESURVEYPASSWORD=secureservice_password
快速开始
设置
设置环境变量:
bash
export LIMESURVEY_URL=https://survey.example.com/index.php/admin/remotecontrol
export LIMESURVEY_USER=admin
export LIMESURVEYPASSWORD=yourpassword
CLI 使用
bash
列出所有调查
python3 scripts/limesurvey.py list-surveys
导出回复
python3 scripts/limesurvey.py export-responses 123456 --format csv -o responses.csv
列出参与者
python3 scripts/limesurvey.py list-participants 123456 --limit 100
从 JSON 添加参与者
python3 scripts/limesurvey.py add-participants 123456 --file participants.json
发送邀请
python3 scripts/limesurvey.py invite-participants 123456
激活调查
python3 scripts/limesurvey.py activate-survey 123456
获取调查统计信息
python3 scripts/limesurvey.py get-summary 123456
Python API 使用
python
from scripts.limesurvey_client import LimeSurveySession
url = https://survey.example.com/index.php/admin/remotecontrol
with LimeSurveySession(url, admin, password) as client:
# 列出调查
surveys = client.call(listsurveys, client.sessionkey)
# 导出回复
encoded = client.call(exportresponses, client.sessionkey,
survey_id, csv)
csvdata = client.decodebase64(encoded)
常见工作流
调查管理
列出所有调查:
python
surveys = client.call(listsurveys, client.sessionkey)
激活调查:
python
result = client.call(activatesurvey, client.sessionkey, survey_id)
获取调查统计信息:
python
stats = client.call(getsummary, client.sessionkey, survey_id, all)
返回:completedresponses, incompleteresponses, token_count 等
复制调查:
python
result = client.call(copysurvey, client.sessionkey,
source_id, New Survey Name)
new_id = result[newsid]
参与者管理
初始化参与者表:
python
使用自定义属性创建表
client.call(activate
tokens, client.sessionkey, survey_id, [1, 2, 3])
添加参与者:
python
participants = [
{email: user@example.com, firstname: John, lastname: Doe},
{email: user2@example.com, firstname: Jane, lastname: Smith}
]
result = client.call(addparticipants, client.sessionkey,
survey_id, participants, True)
发送邀请:
python
发送给特定令牌
token_ids = [1, 2, 3]
result = client.call(invite
participants, client.sessionkey,
survey
id, tokenids)
或发送给所有待处理
result = client.call(invite
participants, client.sessionkey,
survey_id, None)
使用过滤器列出参与者:
python
查找未使用的令牌
participants = client.call(list
participants, client.sessionkey,
survey_id, 0, 100, True)
按自定义属性查找
participants = client.call(list
participants, client.sessionkey,
survey_id, 0, 1000, False, False,
{attribute_1: ACME Corp})
回复操作
导出所有回复:
python
encoded = client.call(exportresponses, client.sessionkey,
survey_id, csv)
csvdata = client.decodebase64(encoded)
with open(responses.csv, w) as f:
f.write(csv_data)
仅导出已完成回复:
python
encoded = client.call(exportresponses, client.sessionkey,
survey_id, csv, None, complete)
按令牌导出:
python
encoded = client.call(exportresponsesbytoken, client.sessionkey,
survey_id, json, [token1, token2])
以编程方式添加回复:
python
response_data = {
G1Q1: Answer text,
G1Q2: 3, # 多选题值
token: xyz123
}
responseid = client.call(addresponse, client.session_key,
surveyid, responsedata)
题目与分组操作
列出分组:
python
groups = client.call(listgroups, client.sessionkey, survey_id)
添加题目分组:
python
groupid = client.call(addgroup, client.sessionkey, surveyid,
Demographics, Basic information)
列出题目:
python
调查中的所有题目
questions = client.call(list
questions, client.sessionkey, survey_id)
特定分组中的题目
questions = client.call(list
questions, client.sessionkey,
survey
id, groupid)
获取题目详情:
python
props = client.call(getquestionproperties, client.session_key,
question_id, [question, type, mandatory])
导出与报告
生成统计信息 PDF:
python
encoded = client.call(exportstatistics, client.sessionkey,
survey_id, pdf, None, 1) # 包含图表
import base64
pdf_data = base64.b64decode(encoded)
with open(stats.pdf, wb) as f:
f.write(pdf_data)
获取提交时间线:
python
timeline = client.call(exporttimeline, client.sessionkey,
survey_id, day, 2024-01-01, 2024-12-31)
for entry in timeline:
print(f{entry[period]}: {entry[count]} submissions)
获取调查字段映射:
python
fieldmap = client.call(getfieldmap, client.sessionkey, survey_id)
将题目代码映射到元数据
错误处理
所有 API 函数在出错时返回状态对象:
python
result = client.call(activatesurvey, client.sessionkey, survey_id)
if isinstance(result, dict) and status in result:
print(fError: {result[status]})
# 常见错误:
# - 无效的会话密钥
# - 无权限
# - 无效的调查 ID
# - 调查已激活
else:
print(Success!)
对连接错误使用 try/except:
python
from scripts.limesurvey_client import LimeSurveyError
try:
with LimeSurveySession(url, username, password) as client:
result = client.call(listsurveys, client.sessionkey)
except LimeSurveyError as e:
print(fAPI error: {e})
参考文档
- - API 参考 — 包含参数和返回值的完整函数参考
- 示例 — 常见任务的实际代码示例
可用函数
会话
- - getsessionkey(username, password) — 创建会话
- releasesessionkey(session_key) — 关闭会话
调查
- - listsurveys(sessionkey) — 列出所有调查
- getsurveyproperties(sessionkey, surveyid, properties) — 获取属性
- setsurveyproperties(sessionkey, surveyid, properties) — 更新属性
- activatesurvey(sessionkey, surveyid) — 激活调查
- deletesurvey(sessionkey, surveyid) — 删除调查
-