A comprehensive suite of functions for interfacing with the 'Survey Solutions' APIs (< https://demo.mysurvey.solutions/apidocs/index.html> and < https://docs.mysurvey.solutions/>). It supports all the current POST, GET, and PATCH requests of the 'REST' API and extends its capabilities by integrating selected 'GraphQL' API queries and mutations when 'REST' API equivalents are not available. Designed for ease of use, it includes several convenience functions to streamline operations. The package ensures that data retrieved from the API is automatically transformed into a single, easy-to-use data frame or data table, optimizing it for subsequent analysis and processing. Additionally, it is specifically designed to facilitate seamless integration into 'shiny' applications, enhancing the interactive web application development experience. Built on the robust 'httr2' package, this version supersedes the previous 'httr'-based implementation. Recognizing the needs of large-scale data operations such as censuses, the package also incorporates features for parallel processing, enhancing its efficiency and scalability.
SurveySolutionsAPIv2 is a comprehensive, production-ready R
interface to the World Bank’s Survey
Solutions Computer-Assisted Personal
Interviewing (CAPI) and Computer-Assisted Web Interviewing (CAWI)
platform.
Built on modern httr2, this package
supersedes the previous httr-based implementation
(SurveySolutionsAPI). It covers the full current REST API (v1 and v2)
as well as complementary GraphQL queries and mutations, providing a
robust foundation for survey operations, quality control dashboards, and
automated data pipelines.
httr2 Architecture: Fast, resilient HTTP communications
with structured error handling via cli and automatic retries for
transient server errors.ConditionExpression), Designer validations (val), and categorical
answer options (answers).include_raw = FALSE produces pure
atomic data.table outputs that serialize cleanly with
data.table::fwrite(), with an opt-in include_raw = TRUE to retain
raw JSON nodes.exportClass).suso_createUSER()), preloaded sample assignments, and offline
basemap management.DT and plotly.install.packages("SurveySolutionsAPIv2")
You can install the latest release directly from GitHub:
# install.packages("remotes")
remotes::install_github("michael-cw/SurveySolutionsAPIv2")
Configure your Survey Solutions server credentials securely using
suso_set_key(). Credentials can be supplied directly or loaded from
environment variables:
library(SurveySolutionsAPIv2)
# Set credentials for the active session
suso_set_key(
suso_server = Sys.getenv("SUSO_SERVER", "https://your-server.mysurvey.solutions"),
suso_user = Sys.getenv("SUSO_USER", "api_user"),
suso_password = Sys.getenv("SUSO_PASSWORD", "secret_pass"),
workspace = "primary"
)
# Test connectivity (returns HTTP 200 on success)
suso_PwCheck()
Retrieve all questionnaires available in the active workspace:
# List questionnaires
quest_list <- suso_getQuestDetails(operation.type = "list")
print(quest_list[, .(Title, Variable, Version, QuestionnaireId)])
Parse the entire questionnaire into four structured data.table
components:
# Extract questionnaire metadata
q_struct <- suso_getQuestDetails(
questID = quest_list$QuestionnaireId[1],
version = quest_list$Version[1],
operation.type = "structure",
include_raw = FALSE # Clean flat tables, ready for data.table::fwrite
)
# Access questions, validations, and answer options
questions <- q_struct$q
validations <- q_struct$val
codebook <- q_struct$answers
Distribute assignments to field enumerators with preloaded sample data:
suso_set_assignments(
questID = quest_list$QuestionnaireId[1],
version = quest_list$Version[1],
responsible = "interviewer01",
quantity = 10,
prefill = list(cluster_id = 101, region = "North")
)
Trigger, monitor, download, and parse export data with a single function:
# Export all approved interviews as Tabular data
survey_data <- suso_export(
questID = quest_list$QuestionnaireId[1],
version = quest_list$Version[1],
type = "Tabular",
workStatus = "ApprovedByHeadquarters",
addTranslation = TRUE
)
# The returned exportClass object contains labeled data tables
summary(survey_data)
Comprehensive documentation and tutorials are available on the companion pkgdown website:
exportClass attributes, and
parallel processing.This project is licensed under the MIT License — see the LICENSE file for details.