Cohort API endpoint

A named subgroup of a project’s subjects, for an analysis or an experimental group.

Table of contents

  1. Endpoints
  2. Fields
  3. List
  4. Add
  5. Detail
  6. Change
  7. Delete
  8. Data model
  9. Usage notes

Endpoints

  • Private portal: https://www.brainstem.org/api/private/stem/cohort/ (needs a token; one record: append <id>/)
  • Public portal: https://www.brainstem.org/api/public/stem/cohort/ (read-only, public projects, no token)
  • Response keys: cohort (detail, create, update), cohorts (list)
  • Permissions: inherited through project (from project)
  • Uniqueness: name, project unique together

Fields

[required] fields must be sent on create; [read-only] fields are returned but cannot be set. A nestable relation can be traversed in filters (filter{field.other}) and sideloaded with include[]=field.*; other relations can only be compared with ids (filter{field}=<id>). See the query syntax.

FieldDescription
idUUID string [read-only]
namestring [required]; max 100 characters
projectproject id [required]
subjectslist of subject ids [required]. Add subjects and reorder them using drag-and-drop.
descriptionstring; nullable
tagslist of strings; filter with filter{tags.name}=<name>

List

  • Allowed portals: private, public
  • Request method: GET
  • URL: https://www.brainstem.org/api/private/stem/cohort/
  • Responses: 200 OK; 401 Not authenticated; 403 Not allowed

Use example (Python API tool)

resp = client.load('cohort', load_all=True)
records = resp['cohorts']

Use example (MATLAB API tool)

resp = client.load('cohort', 'load_all', true);
records = resp.cohorts;

Response example

{
    "cohorts": [
        {
            "id": "<id>",
            "name": "Cohort 1",
            "project": "<project-id>",
            "subjects": [
                "<subject-id>"
            ],
            "description": "",
            "tags": []
        }
    ],
    "meta": {
        "page": 1,
        "per_page": 100,
        "total_results": 1,
        "total_pages": 1
    }
}

Add

  • Allowed portals: private
  • Request method: POST
  • URL: https://www.brainstem.org/api/private/stem/cohort/
  • Data: JSON object with at least the required fields
  • Responses: 201 Created; 400 Bad request (validation errors per field); 403 Not allowed

Use example (Python API tool)

resp = client.save('cohort', data={"name": "Cohort 1", "project": "<project-id>", "subjects": ["<subject-id>"]})
record = resp.json()['cohort']

Use example (MATLAB API tool)

created = client.save(struct('name', 'Cohort 1', 'project', '<project-id>', 'subjects', {{'<subject-id>'}}), 'cohort');
record = created.cohort;

Detail

  • Allowed portals: private, public
  • Request method: GET
  • URL: https://www.brainstem.org/api/private/stem/cohort/<id>/
  • Responses: 200 OK; 403 Not allowed; 404 Not found

Use example (Python API tool)

resp = client.load('cohort', id='<id>')
record = resp.json()['cohort']

Use example (MATLAB API tool)

out = client.load('cohort', 'id', '<id>');
record = out.cohort;

Response example

{
    "cohort": {
        "id": "<id>",
        "name": "Cohort 1",
        "project": "<project-id>",
        "subjects": [
            "<subject-id>"
        ],
        "description": "",
        "tags": []
    }
}

Change

  • Allowed portals: private
  • Request method: PATCH
  • URL: https://www.brainstem.org/api/private/stem/cohort/<id>/
  • Data: JSON object with the fields to change. Lists (projects, tags, …) and JSON payloads (details, coordinates) are replaced as a whole: read the record first and send the full list or object.
  • Responses: 200 OK; 400 Bad request; 403 Not allowed; 404 Not found

Use example (Python API tool)

resp = client.save('cohort', id='<id>', data={"name": "Cohort 1 (renamed)"})

Use example (MATLAB API tool)

client.save(struct('id', '<id>', 'name', 'Cohort 1 (renamed)'), 'cohort', 'method', 'patch');

Delete

  • Allowed portals: private
  • Request method: DELETE
  • URL: https://www.brainstem.org/api/private/stem/cohort/<id>/
  • Responses: 204 Deleted; 400 Still referenced by other records; 403 Not allowed; 404 Not found

Use example (Python API tool)

resp = client.delete('cohort', id='<id>')

Use example (MATLAB API tool)

client.delete('<id>', 'cohort');

Data model

The fields are described for the web forms on the Cohort data model page.

Usage notes

  • Every subject in subjects must belong to the cohort’s project; otherwise the request is refused with 400. The order of subjects is kept.