LabKey's mobile client API provides enrollment services and data storage for mobile phone client applications. Participants, using a mobile application, can request enrollment in a study, withdraw from a study, and optionally, have their data deleted upon un-enrollment. The response may include an optional language property in the metadata, which is stored for analyst use.
Survey responses are stored in dynamically generated tables on the server.
Upgrade note: In earlier versions, the controller name "mobileAppStudy" was used. This has been changed to "response" as of release 21.3 (March 2021). The old name will still work, but should be updated for future releases.
Response Services - API Details
Response services provide ways to enroll participant in a study, submit responses, and fetch responses from the Response Server.
Enroll
Enrolls a participant in a study on the server. The response includes a globally unique
participantId (as "appToken" or <application-token>). This participantId is used in subsequent communication with the mobile app.
Request:
Method | URL |
---|
POST | /response-enroll.api |
Parameters | Type | Values/Description |
---|
studyId (required) | string | study identifier: A pre-existing study on the server. |
token (required) | string | enrollmentToken: Enrollment token string provided by the participant. Token validation is case-insensitive. The token is used only once for enrollment; previously enrolled tokens cannot be used again. |
allowDataSharing (required) | string | Whether the participant consents to sharing data with third parties. Valid values: "true", "false", "NA" |
language | string | Optional code for user-language. English (en) and Spanish (es) are supported. |
Response:
Params | Values |
---|
success | boolean |
exception | string; |
data | { "appToken": string (the participant ID) } |
errors | [ { "msg": string, "field": string, "id": string, token, "message": string, "severity": string } ] |
Afterwards, all submissions to the server are done using the participantID (returned as the "appToken").
ValidateEnrollmentToken
Validates an enrollment token, but does not actually enroll the participant. When successful, returns a JSON object that includes the names and values of all
pre-enrollment participant properties associated with that participant.
Request:
Method | URL |
---|
GET | /response-validateEnrollmentToken.api |
Params | Type | Values/Description |
---|
studyId (required) | string | study identifier: A pre-existing study on the server. |
token (required) | string | enrollmentToken: Enrollment token string provided by the participant. Token validation is case-insensitive. The token is used only once for enrollment; previously enrolled tokens cannot be used again. |
language | string | Optional code for user-language. English (en) and Spanish (es) are supported. |
Response:
Params | Values |
---|
success | boolean; false |
exception | string; |
errors | [ { "msg": string, "field": string, "id": string, token "message": string, "severity":string } ] |
ProcessResponse
Saves survey responses from an activity to the study. No parameters in the URL string, but the JSON object provided in the POST body contains the participantId.
Request:
Method | URL |
---|
POST | /response-processResponse.api |
Params | Values |
---|
response | { "type": string, questionnaire or activetask "metadata": dictionary; activity info { "studyId": string, study identifier "activityId": string, activity identifier "name": string, activity name "version": string, activity version "activityRunId":string run id for the activity } "participantId": string, participant identifier "data": dictionary; activity info { "startTime": string, start time of activity "endTime": string, end time of activity "resultType": string;, "results": array results of each step in activity <refer to the "WCP - Schemas and Structures" topic>> } } |
Details of the
results array contents can be found here:
WCP - Schemas and StructuresResponse:
Params | Values |
---|
success | boolean |
WithdrawFromStudy
Withdraw (un-enroll) a participant from a study. Option to retain or delete data.
Request:
Method | URL |
---|
POST | /response-withdrawFromStudy.api |
Params | Type | Values/Description |
---|
participantId (required) | string | participant identifier; The "appToken" value returned at enrollment. |
delete (optional) | boolean | Optional boolean to delete the withdrawn participant's response data. Defaults to FALSE. |
Response:
Params | Values |
---|
exception | string |
success | boolean |
status | string |
Resolve Enrollment Token
This API is used to search the study using enrollment token. Given a valid enrollment token, returns the studyId associated with the folder where the token was generated, whether or not that token has already been used for enrollment.
Request:
Method | URL |
---|
POST | /response-resolveEnrollmentToken.api |
Parameter | Type | Values |
---|
token (required) | string | Enrollment token provided by the participant. |
Response:
Params | Values |
---|
exception | string |
Query APIs
Two LabKey Query APIs are important when working with MyStudies. Both employ special authentication and filtering to just the current participant. Learn more here:
Query Example: Get Participant Response
To fetch responses for a provided question, activity and study identifiers, you can use LabKey’s executeSQL api.
Request:
Method | URL |
---|
POST | /response-executeSQL |
Parameter | Type | Values/Description |
---|
sql | string | query to retrieve response |
participantId | string | |
Response:
Depending on sql query, response varies.
Examples
Example URLs to invoke:
http://localhost:8080/response-enroll.api?studyId=<study-id>&token=<enrollment-token>&allowDataSharing=NA
http://localhost:8080/response-validateEnrollmentToken.api?studyId=<study-id>&token=<enrollment-token>&allowDataSharing=NA
http://localhost:8080/response-withdrawFromStudy.api?participantId=<participantId>&delete=<boolean>
http://localhost:8080/response-processResponse.api? (The <participantId> is provided in the posted JSON body.)
On Success
When an action is successful, the server responds with a JSON object with the following format.
{
"success" : true
"data" :
{
"appToken" : string, participantId
}
}
In the case of
validateEnrollmentToken, pre-enrollment properties will be returned.
{
"success": true,
"data": {
"preEnrollmentParticipantProperties": [
{
"propertyId": string, ExternalConsentStatus
"value": string Fully Consented
}, {
"propertyId": string, Cohort
"value": string Traditional Diet
}
]
}
}
On Error
Error responses have the following format:
{
"exception" : string, message
"success" : false,
"errors" : [
{
"msg" : string, message,
"field" : string, form/studyId/token
"id" : string, form/studyId/token",
"message" : string message
}
]
}
As an example, an invalid enrollment token might generate:
{
"success": false,
"exception": string, InvalidToken
"errors": [{
"message":: string, Invalid token supplied
"field": : string, EnrollmentToken
"id": : string
}]
}
Error Cases
The following error cases are handled:
Message | Field | Cause |
---|
Invalid input format | form | The data provided in the API could not be deserialized properly. |
StudyId is required for enrollment | form | Empty or no studyId provided. |
Study with studyId "XXX" does not exist | studyId | Invalid studyId provided. |
Token already in use | form | The provided token already has a participant id associated with it in the study's container. |
Invalid token: "YYY" | token | The checksum for the token is incorrect. |
Unknown token: "ZZZ" | token | The token provided has a valid checksum but it is not associated with the given studyId. |
Token is not associated with a study ID | token | There is no study associated with the submitted token. |
Token is required. | form | The study associated with the given studyId requires an enrollment token and none was provided. This message is returned unless the language is set to Spanish. |
Se requiere un token. | form | The language is set to Spanish, the study associated with the given studyId requires an enrollment token, and none was provided. |
Participant Properties
The WCP (web configuration portal) can provide definitions for participant properties to be included with other information in the mobile app study. For example, if an application wants to survey participants prior to a next appointment, data needs to be stored for each participant about the timing of appointments for that particular participant. When provided, the list of participant property definitions is stored in the study folder, and this list can be queried via the standard selectRows API. In the example, the mobile app is able to ascertain when to send the next survey.
Properties can be either pre- or post-enrollment; though query is typically done only of post-enrollment properties. When the application retrieves values from participant properties, they will see only the properties for the specific participant they are viewing.
Participant properties are keyed on the enrollment token, and post-enrollment properties can also be queried by participantID. The specific participant properties available for a given application will vary. You can see the listing in the MobileAppResponse schema, under Participant Properties.
Participant Property Attributes
When participant properties are defined and passed to the response server, they have the following attributes:
Attribute | type/values | Description |
---|
propertyId | string | A unique identifier under study for participant property. |
propertyName | string | A user friendly name for participant property. eg: Date Of Appointment. |
propertyType | PreEnrollment/PostEnrollment | This defines what type of participant property it is. |
propertyDataType | string | The type of the property (string, boolean, etc) |
shouldRefresh | boolean | Whether to refresh participant property value periodically or not. |
dataSource | ExternalSystem/Other | Defines from where the value will be populated. |
status | active/deactivated | Status of participant property |
value | depends on type | value of participant property sent by external system |
Multiple Language Support
Studies may be configured to support user-facing communication in multiple languages. At present, English is the default and Spanish language is also supported.
Note that all administrative actions for setting up the study and resources for researchers/data analysts will be presented in English. The multiple language support applies only to the information and messages shown to the user of the mobile app.
The Response Server collects free-text responses as entered by the participant. The response JSON includes an optional language property in the metadata. This gets parsed, translated into a friendly name, and saved in a new column in the Response table. Language codes and names are sourced from
Both the
Enroll and
ValidateEnrollmentToken APIs accept the language parameter in order to return a language specific error message if a token is not supplied.
- English: Token is required.
- Spanish: Se requiere un token.
Related Topics