Skip to main content

Reading Cozie data

Data flow from database to Cozie

Overview

The information shown in the 'Watch Survey' section on the 'Data' tab of the Cozie app is fetched from InfluxDB using the read API. These fields are a way for the participant to receive immediate feedback about the validity of their responses.

Watch Survey section in Data tab

In the example above the, '100' is retrieved from the 'Settings' tab. The other three fields are retrieved using the read API.

The response body of the read API looks as follows:

Read API response body
{
"ws_survey_count_valid":"0",
"ws_survey_count_invalid":"0",
"ws_timestamp_survey_last":"-"
}

Changes in the Cozie app

In order to have Cozie app read the data from your own backend, you need to update API Read URL and the API Read Key in the 'Backend' tab of the Cozie app.

Lambda function code

Lambda configuration

ConfigurationValueComment
General configuration
Memory512 MB
Ephemeral storage512 MBdefault value
Timeout0 min 30 sec
Triggers
API Gatewaycozie-apple-v3-researcher-api
Environment variables
DB_HOSTXXX.influxcloud.net(replace 'XXX')
DB_NAMEcozie-apple
DB_PASSWORDXXX(replace 'XXX')
DB_PORT8086
DB_USERCozie-Apple-Lambda-Reader-App-API
Layers
AWSSDKPandas-Python311AWS Layer for Pandas
InfluxCustom layer for InfluxDB client

API Gateway configuration

ConfigurationValueComment
Proxy resourcedisableddefault
Resource path/
Resource nameread-queue
CORS (Cross Origin Resource Sharing)enabled
Method details
Method typeANY
Integration typeLambda function
Lambda proxy integrationenabled
Lambda functionarn:aws:lambda:[region]:[Accound ID]:function:cozie-apple-v3-app-readcheck dropdown menu
Default timeoutenabled29 seconds (default)
Method request settings
AuthorizationNonedefault
Request validatorNonedefault
API key requiredenabled
URL query string parameters
leave emptydefault
HTTP request headers
leave emptydefault
Request body
leave emptydefault