# Project controller (/project) - Watch

The project controller contains many endpoints related to projects, which is where all data is stored. The endpoints are divided in five groups:

  • General
    Get information about available projects and tables within projects, and run a basic check of access and system status.

  • Users
    Manage users that are members of a project.

  • Read
    Read user data from tables.

  • Write
    Create, update or delete user data in tables.

  • Watch
    Watch for changes of user data in tables, and for changes of project members.

# All project endpoints

Below are all endpoints in the entire project controller in alphabetical order. Endpoints in the current group are in bold.

/project/list (GET)
/project/list/all (GET)
/project/{project}/check (GET)
/project/{project}/subjects/watch/register (POST)
/project/{project}/subjects/watch/unregister/{id} (POST)
/project/{project}/subjects/watch/{id} (GET)
/project/{project}/table/{table} (GET)
/project/{project}/table/{table} (POST)
/project/{project}/table/{table} (DELETE)
/project/{project}/table/{table}/filter/delete (POST)
/project/{project}/table/{table}/filter/get (POST)
/project/{project}/table/{table}/filter/get/first (POST)
/project/{project}/table/{table}/filter/get/last (POST)
/project/{project}/table/{table}/first (GET)
/project/{project}/table/{table}/last (GET)
/project/{project}/table/{table}/purge (DELETE)
/project/{project}/table/{table}/spec (GET)
/project/{project}/table/{table}/watch/register (POST)
/project/{project}/table/{table}/watch/unregister/{id} (POST)
/project/{project}/table/{table}/watch/{id} (GET)
/project/{project}/table/{table}/{recordId} (GET)
/project/{project}/table/{table}/{recordId} (PUT)
/project/{project}/table/{table}/{recordId} (DELETE)
/project/{project}/tables (GET)
/project/{project}/user (POST)
/project/{project}/user (DELETE)
/project/{project}/users (GET)

# /{project}/table/{table}/watch/register

/project/{project}/table/{table}/watch/register POST
Description
Adds a registration to watch a table for new database actions for the specified subject.

There are two ways to watch for new database actions. The preferred way is with a callback URL. The other way is with long polling using

/project/{project}/table/{table}/watch/{id}

. If you want to receive a callback, you should specify the callback URL.

If a registration with the same parameters already exists, it does not create a new registration, but re-uses the current registration. Any client that was watching that registration will be cancelled. This method returns a registration ID that you can pass to

/project/{project}/table/{table}/watch/{id}

.

If you no longer want to watch the table, you can call

/project/{project}/table/{table}/watch/unregister/{id}

. The server also cleans up registrations automatically. Registrations with a callback URL are removed if the callback failed at least 5 times for at least 24 hours in a row. Registrations without a callback are removed if they haven’t been watched for an hour.
Finally a callback can indicate deletion through its response. It should return 404 Not Found with this JSON payload:

{ "error": "callback_expired" }

The callback will be called with HTTP method POST. Its payload will be a JSON object with these properties:

project
Project code
table
Name of the table
subjects
Array with user IDs of the subjects where database actions occurred.
Example:
{
    "project": "default",
    "table": "steps",
    "subjects": [ "b43f784d76c44e7a9ae0370b91521753" ]
}
Admins may set parameter ‘anyUser’ so they are notified whenever a database action occurs for any user in the specified table.
Authorization
Users need to have access to the specified project. Admins can access all projects.
All users can access their own data within a project that they can access.
Patients can only access their own data.
Professionals can access the data of users to whom they were granted access.
Admins can access all data.
URL parameters
{project}
Project code (see

/project/list

)
{table}
Name of the table (see

/project/{project}/tables

)
user
(optional) User ID of the user for whom you want to watch database actions. Omit or leave empty to watch actions for yourself. This field is ignored if ‘anyUser’ is set.
anyUser
(optional) Set to true if you want to be notified when a database action for any user occurs in the specified table. Parameter ‘user’ will be ignored. Only admins can set this to true. Default: false.
callbackUrl
(optional) If you want to receive a callback when a new database action occurs, you should set the callback URL here.
reset
(optional) Set to true if any pending database actions in an existing registration should be cleared. Default: false.
Content
Response (string)
Registration ID.
Example
Request
POST https://www.example.com/servlets/senseeact/v6.1.0/project/default/table/steps/watch/register
    ?user=b43f784d76c44e7a9ae0370b91521753
    &callbackUrl=https://www.example.com/callback
    &reset=false
X-Auth-Token: ...
Response
6205a45f4afc4e31af67c6315963745b
Request (with anyUser)
GET https://www.example.com/servlets/senseeact/v6.1.0/project/default/table/steps/watch/register
    ?anyUser=true
    &callbackUrl=https://www.example.com/callback
    &reset=false
X-Auth-Token: ...
Response
6205a45f4afc4e31af67c6315963745b

# /{project}/table/{table}/watch/{id}

/project/{project}/table/{table}/watch/{id} GET
Description
Waits up to one minute until a database action occurs for the specified watch registration or until the watch is unregistered.

As soon as there are new database actions, this method returns them. This may include actions that occurred since the registration or last watch and that you haven’t received yet. If no actions occur before the time-out, this method returns an empty list.

Only one client can watch a specific registration. If another client registers or starts to watch the same registration, then the current client will be cancelled. This means that this method will return immediately with an empty list result. Likewise, when you call this method, any other clients that were watching the same registration, will be cancelled.

If you disconnect the client during a watch, the server may still send an action and think that you received it. If you start a new session and don’t want to miss any actions, it’s best to call a read endpoint after the watch registration.

You should specify a registration ID that you got from

/project/{project}/table/{table}/watch/register

. If you no longer want to watch the table, you should call

/project/{project}/table/{table}/watch/unregister/{id}

. Note that the server may automatically clean up registrations that haven’t been watched for an hour.

Authorization
The specified registration must have been made by the same user. The authorization for this registration must still hold.
URL parameters
{project}
Project code (see

/project/list

)
{table}
Name of the table (see

/project/{project}/tables

)
Content
Response
JSON array with user IDs of the users for which database actions occurred.
Example
Request
GET https://www.example.com/servlets/senseeact/v6.1.0/project/default/table/steps/watch
    /6205a45f4afc4e31af67c6315963745b
X-Auth-Token: ...
Response
[
    "b43f784d76c44e7a9ae0370b91521753",
    ...
]

# /{project}/table/{table}/watch/unregister/{id}

/project/{project}/table/{table}/watch/unregister/{id} POST
Description
Removes a registration that was added with

/project/{project}/table/{table}/watch/register

. Any client that was watching this registration, will be cancelled. If the registration doesn’t exist, this method has no effect.
Authorization
The specified registration must have been made by the same user.
URL parameters
{project}
Project code (see

/project/list

)
{table}
Name of the table (see

/project/{project}/tables

)
Content
Response
Example
Request
POST https://www.example.com/servlets/senseeact/v6.1.0/project/default/table/steps/watch
    /unregister/6205a45f4afc4e31af67c6315963745b
X-Auth-Token: ...
Response

# /{project}/subjects/watch/register

/project/{project}/subjects/watch/register POST
Description
Adds a registration to watch active subjects that you can access within the specified project.

This method returns a registration ID that you can pass to

/project/{project}/subjects/watch/{id}

. If a registration with the same parameters already exists, then this method returns the ID of that registration. Any client that was watching that registration will be cancelled.

If you no longer want to watch active subjects, you should call

/project/{project}/subjects/watch/unregister/{id}

. Note that the server may automatically clean up registrations that haven’t been watched for an hour.

Authorization
Users need to have access to the specified project. Admins can access all projects.
URL parameters
{project}
Project code (see

/project/list

)
reset
(optional) Set to true if any pending subject events in an existing registration should be cleared. Default: false.
Content
Response (string)
Registration ID.
Example
Request
POST https://www.example.com/servlets/senseeact/v6.1.0/project/default/subjects/watch/register
    ?reset=false
X-Auth-Token: ...
Response
6205a45f4afc4e31af67c6315963745b

# /{project}/subjects/watch/{id}

/project/{project}/subjects/watch/{id} GET
Description
Waits up to one minute until a subject event occurs for the specified watch registration or until the watch is unregistered. You receive events when an active subject is added or removed, or when the user profile of an active subject is changed.

As soon as there are new events, this method returns those events. This may include events that occurred since the registration or last watch and that you haven’t received yet. If no events occur before the time-out, this method returns an empty list.

Only one client can watch a specific registration. If another client registers or starts to watch the same registration, then the current client will be cancelled. This means that this method will return immediately with an empty list result. Likewise, when you call this method, any other clients that were watching the same registration, will be cancelled.

If you disconnect the client during a watch, the server may still send an event and think that you received it. If you start a new session and don’t want to miss any events, it’s best to call a read endpoint after the watch registration.

You should specify a registration ID that you got from

/project/{project}/subjects/watch/register

. If you no longer want to watch the subjects, you should call

/project/{project}/subjects/watch/unregister/{id}

. Note that the server may automatically clean up registrations that haven’t been watched for an hour.

Authorization
The specified registration must have been made by the same user. The authorization for this registration must still hold.
URL parameters
{project}
Project code (see

/project/list

)
{id}
Content
Response
JSON array with subject events. Each event is a JSON object. There are three types of events as detailed below.

When a subject is added:

type
ADDED
user
User ID of the subject user

When a subject is removed:

type
REMOVED
user
User ID of the subject user

When the user profile of a subject is updated:

type
PROFILE_UPDATED
user
User ID of the subject user
oldProfile
Previous user profile. See

GET /user/

for the complete specification.
newProfile
New user profile.
Example
Request
GET https://www.example.com/servlets/senseeact/v6.1.0/project/default/subjects/watch
    /6205a45f4afc4e31af67c6315963745b
X-Auth-Token: ...
Response
[
    {
        "type": "ADDED",
        "user": "b43f784d76c44e7a9ae0370b91521753"
    },
    {
        "type": "REMOVED",
        "user": "b43f784d76c44e7a9ae0370b91521753"
    },
    {
        "type": "PROFILE_UPDATED",
        "user": "b43f784d76c44e7a9ae0370b91521753",
        "oldProfile": {
            "email": "user@example.com",
            "role": "PATIENT"
            ...
        },
        "newProfile": {
            "email": "user@example.com",
            "role": "PATIENT"
            ...
        }
    }
]

# /{project}/subjects/watch/unregister/{id}

/project/{project}/subjects/watch/unregister/{id} POST
Description
Removes a registration that was added with

/project/{project}/subjects/watch/register

. Any client that was watching this registration, will be cancelled. If the registration doesn’t exist, this method has no effect.
Authorization
The specified registration must have been made by the same user.
URL parameters
{project}
Project code (see

/project/list

)
{id}
Content
Response
Example
Request
POST https://www.example.com/servlets/senseeact/v6.1.0/project/default/subjects/watch
    /unregister/6205a45f4afc4e31af67c6315963745b
X-Auth-Token: ...
Response