# queryRecords

This method returns a list of records owned by the current user. By default, you only get the records created by your application. To query the records from another application, you must filter by the license id of this application.

## Parameters

| Name                  | Type               | Required | Description                                                                                                                                                                                                                                                                                                    |
| --------------------- | ------------------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| cortexToken           | `string`           | yes      | A token returned by [authorize](/cortex-api/authentication/authorize.md).                                                                                                                                                                                                                                      |
| query                 | `object`           | yes      | An object to filter the records.                                                                                                                                                                                                                                                                               |
| orderBy               | `array of objects` | yes      | Specify how to sort the records.                                                                                                                                                                                                                                                                               |
| limit                 | `number`           | no       | The maximum number of records that this method should return. A limit of zero means no maximum.                                                                                                                                                                                                                |
| offset                | `number`           | no       | <p>The number of record that this method should skip before returning the result.<br>If the limit is zero, then Cortex will ignore this parameter.</p>                                                                                                                                                         |
| includeMarkers        | `boolean`          | no       | <p>If <code>true</code> then the <a href="/pages/-Lg6tuTXvCwj8nvKobQQ">record objects</a> in the result will include the markers linked to each record. The default value is <code>false</code> because a record may have a large number of markers.</p><p><em>This parameter was added in Cortex 2.1</em></p> |
| includeSyncStatusInfo | `boolean`          | no       | <p>If <code>true</code> then the record object in the result will include  the field "syncStatus". This field tells you if the record was uploaded to the EMOTIV cloud or not.</p><p>The default value is <code>false</code>.</p><p><em>This parameter was added in Cortex 2.6.3</em></p>                      |

{% hint style="danger" %}
Depending on the query, this method may return a lot of records. To avoid performance issues, you should always set an offset and a limit.
{% endhint %}

### query

The **query** object can contain one or more of these fields:

| Name             | Type     | Description                                                                                                 |
| ---------------- | -------- | ----------------------------------------------------------------------------------------------------------- |
| licenseId        | `string` | Set this parameter to filter the records by their license.                                                  |
| applicationId    | `string` | If you set the **licenseId**, then you can set this parameter to further filter the records by application. |
| keyword          | `string` | Set this parameter to filter the records by title, description, or subject name.                            |
| startDatetime    | `object` | An object with fields "from" and "to" to filter the records by their start date time.                       |
| modifiedDatetime | `object` | An object with fields "from" and "to" to filter the records by their modification date time.                |
| duration         | `object` | An object with fields "from" and "to" to filter the records by their duration.                              |

### orderBy

The **orderBy** parameters is an array of objects, similar to the orderBy clause of a SQL request.

Each object must have a single attribute. The key of the attribute is the name of record's field you want to order by. The value of the attribute must be "ASC" or "DESC", to order is ascending or descending order.

For example, to order the records by their start date, in descending order, you must use the object **`{"startDatetime":"DESC"}`**. To sort the records by title, in alphabetical order, you must use **`{"title":"ASC"}`**.

You can order the records by these fields: title, description, startDatetime, modifiedDatetime, duration, subjectName, applicationId.\
\&#xNAN;*The option to order by applicationId was added in Cortex 2.5.0*

### limit and offset

These parameters are to implement pagination. It useful if you want to display the records in a UI. You must order the results to use these parameters.

First you should call this method with an **offset** of zero, and a **limit** of X. In the response, check the value of **count.** If **count** is greater than the limit, then you should call this method again with an offset of X. And then with an offset of 2\*X, 3\*X... until you get all the records for your query.&#x20;

## Result

The result is an object that includes these fields:

| Name    | Type               | Description                                                         |
| ------- | ------------------ | ------------------------------------------------------------------- |
| records | `array of objects` | An array of [record objects](/cortex-api/records/record-object.md). |
| count   | `number`           | The total number of records that match the query.                   |
| limit   | `number`           | The limit you specified in the parameters.                          |
| offset  | `number`           | The offset you specified in the parameters.                         |

## Examples

Get the 10 most recent records created by EmotivPRO.&#x20;

{% tabs %}
{% tab title="Request" %}

```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "queryRecords",
    "params": {
        "cortexToken": "xxx",
        "limit": 10,
        "offset": 0,
        "orderBy": [
            { "startDatetime": "DESC" }
        ],
        "query": {
            "applicationId": "com.emotiv.emotivpro",
            "licenseId": "yyy"
        },
        "includeSyncStatusInfo": true
    }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "count": 1,
    "limit": 10,
    "offset": 0,
    "records": [{
      "applicationId": "com.emotiv.emotivpro",
      "applicationVersion": "2.6.3",
      "demographics": {
        "uuid": "",
        "validated": false
      },
      "description": "A simple experiment with a drone",
      "endDatetime": "2021-01-06T16:32:50.572490+07:00",
      "experimentId": 0,
      "headbandPosition": null,
      "licenseId": "yyy",
      "licenseScope": ["pm", "eeg"],
      "localOnly": false,
      "ownerId": "ddeca960-9336-4a51-a2d2-9cb6e8fd5524",
      "startDatetime": "2021-01-06T16:32:13.431865+07:00",
      "subject": {
        "subjectName": "Ben Kenobi"
      },
      "syncStatus": {
        "status": "neverUploaded"
      },
      "tags": [],
      "title": "Experiment 42",
      "uuid": "1f2a8f85-7200-400a-a8f0-fd5c0b331852"
    }]
  }
}
```

{% endtab %}
{% endtabs %}

Get some records using a keyword.

{% tabs %}
{% tab title="Request" %}

```javascript
{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "queryRecords",
  "params": {
    "cortexToken": "xxx",
    "includeMarkers": true,
    "limit": 2,
    "offset": 0,
    "orderBy": [
      {
        "startDatetime": "DESC"
      }
    ],
    "query": {
      "keyword": "Cortex Example"
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "count": 9,
    "limit": 2,
    "offset": 0,
    "records": [
      {
        "applicationId": "com.xxx.cortex-examples",
        "applicationVersion": "1.0",
        "description": "",
        "endDatetime": "2020-03-09T15:59:34.794356+07:00",
        "experimentId": 0,
        "headbandPosition": null,
        "licenseId": "xxx",
        "licenseScope": [
          "pm",
          "eeg"
        ],
        "localOnly": false,
        "markers": [
          {
            "endDatetime": "2020-03-09T15:59:09.680802+07:00",
            "extras": {},
            "label": "test1",
            "port": "Cortex Example",
            "startDatetime": "2020-03-09T15:59:09.680802+07:00",
            "type": "instance",
            "uuid": "ba8ed3a9-3e0b-4a17-9227-96ae05fa1767",
            "value": 41
          },
          {
            "endDatetime": "2020-03-09T15:59:25.873059+07:00",
            "extras": {},
            "label": "test2",
            "port": "Cortex Example",
            "startDatetime": "2020-03-09T15:59:16.867054+07:00",
            "type": "interval",
            "uuid": "2cfe93cc-f242-49d6-8165-7b13147e7c10",
            "value": 42
          }
        ],
        "ownerId": "94f7c5ed-3d24-4c29-8243-96aa7db80d4a",
        "startDatetime": "2020-03-09T15:59:04.344671+07:00",
        "subject": {
          "subjectName": "Bob"
        },
        "tags": [],
        "title": "Cortex Examples C++",
        "uuid": "b26f35c3-42ee-4612-a9b9-09af04c2ba37"
      },
      {
        "applicationId": "com.xxx.cortex-examples",
        "applicationVersion": "1.0",
        "description": "",
        "endDatetime": "2020-03-09T15:58:37.792248+07:00",
        "experimentId": 0,
        "headbandPosition": null,
        "licenseId": "xxx",
        "licenseScope": [
          "pm",
          "eeg"
        ],
        "localOnly": false,
        "markers": [
          {
            "endDatetime": "2020-03-09T15:58:12.875515+07:00",
            "extras": {},
            "label": "test1",
            "port": "Cortex Example",
            "startDatetime": "2020-03-09T15:58:12.875515+07:00",
            "type": "instance",
            "uuid": "e22d46a0-480a-452a-a65e-d6b4448e3f7b",
            "value": 41
          },
          {
            "endDatetime": "2020-03-09T15:58:28.872019+07:00",
            "extras": {},
            "label": "test2",
            "port": "Cortex Example",
            "startDatetime": "2020-03-09T15:58:20.873850+07:00",
            "type": "interval",
            "uuid": "c8fd9191-43da-4e28-970d-bf9f24404c8a",
            "value": 42
          }
        ],
        "ownerId": "94f7c5ed-3d24-4c29-8243-96aa7db80d4a",
        "startDatetime": "2020-03-09T15:58:08.036369+07:00",
        "subject": {
          "subjectName": "Marie"
        },
        "tags": [],
        "title": "Cortex Examples C++",
        "uuid": "33d2c56a-4cdf-4e2b-a5bb-db127f838248"
      }
    ]
  }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://emotiv.gitbook.io/cortex-api/records/queryrecords.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
