# exportRecord

This method is to export one or more records to EDF or CSV files.

You can export the raw EEG data, the motion data, the performance metrics and the band powers. The available data streams depend on the license of the record. You can check the field **licenceScope** in the [Record object](https://emotiv.gitbook.io/cortex-api/records/record-object) to know which data streams are available.

By default, you can only export the records that were created by your application. If you want to export a record that was created by another application (e.g. [Emotiv PRO](https://www.emotiv.com/emotivpro/) or [EMOTIV LABS](https://www.emotiv.com/emotiv-labs/)) then you must provide the license id of this application in the parameter **licenseIds.**

In order to export a record created by [EMOTIV LABS](https://www.emotiv.com/emotiv-labs/), the current [Cortex user](https://emotiv.gitbook.io/cortex-api/authentication/getuserlogin) must be the owner of the LABS experiment.&#x20;

You must [stop the record](https://emotiv.gitbook.io/cortex-api/records/stoprecord) before you can export it. If you want to export a record immediately after you stop it then you must  wait for the [warning 30](https://emotiv.gitbook.io/cortex-api/warning-objects) before you try to export.

The format of the exported files is described in [EmotivPRO user manual](https://emotiv.gitbook.io/emotivpro-v3/managing-your-eeg-data-recordings/exporting-an-eeg-data-recording).

*This method was added in Cortex 2.1.1 to all desktop versions of Cortex. It was added to iOS and Android in Cortex 2.7.0*

## Parameters

<table data-header-hidden><thead><tr><th width="227.28045325779038">Name</th><th>Type</th><th width="150">Required</th><th>Description</th></tr></thead><tbody><tr><td>Name</td><td>Type</td><td>Required</td><td>Description</td></tr><tr><td>cortexToken</td><td><code>string</code></td><td>yes</td><td>A token returned by <a href="../authentication/authorize">authorize</a>.</td></tr><tr><td>recordIds</td><td><code>array of strings</code></td><td>yes</td><td>An array of record ids. These are the ids of the records you want to export.</td></tr><tr><td>folder</td><td><code>string</code></td><td>yes</td><td><p>The path of a local folder. Cortex will write the exported files in that folder. You must create this folder before you call this method. Cortex will return an error if the folder doesn't exist.</p><p></p><p>On iOS, this parameter doesn't exist. Cortex exports the data to the "Documents" folder of the current application.</p></td></tr><tr><td>streamTypes</td><td><code>array of strings</code></td><td>yes</td><td>List of the data streams you want to export.</td></tr><tr><td>format</td><td><code>string</code></td><td>yes</td><td>The format of the exported files. Must be "EDF", "EDFPLUS", "BDFPLUS" or "CSV".</td></tr><tr><td>version</td><td><code>string</code></td><td>no</td><td><p>If the format is "EDF", then you must omit this parameter.</p><p>If the format is "CSV", then this parameter must be "V1" or "V2".</p></td></tr><tr><td>licenseIds</td><td><code>array of strings</code></td><td>no</td><td><p>The default value is an empty list, which means that you can only export the records created by your application.<br>You can provide the license ID of other applications in order to export the records created by these applications.</p><p><em>This parameter was added in Cortex 2.6.3</em></p></td></tr><tr><td>includeDemographics</td><td><code>boolean</code></td><td>no</td><td><p>If <code>true</code> then the exported JSON file will include the demographic data of the user. It is only for the records created by <a href="https://www.emotiv.com/emotiv-labs/">EMOTIV LABS</a>.</p><p>The default value is <code>false</code>.</p><p><em>This parameter was added in Cortex 2.6.3</em></p></td></tr><tr><td>includeSurvey</td><td><code>boolean</code></td><td>no</td><td><p>If <code>true</code> then the exported JSON file will include the survey data of the record. It is only for the records created by <a href="https://www.emotiv.com/emotiv-labs/">EMOTIV LABS</a>.</p><p>The default value is <code>false</code>.</p><p><em>This parameter was added in Cortex 2.6.3</em><br><br>From Cortex 3.5.0, survey data will be exported in a separate CSV file (along with JSON file).</p></td></tr><tr><td>includeMarkerExtraInfos</td><td><code>boolean</code></td><td>no</td><td><p>If <code>true</code> then the markers of the records will be exported to a CSV file. This file is compatible with <a href="https://sccn.ucsd.edu/eeglab">EEGLAB</a><strong>.</strong></p><p>The default value is <code>false</code>.</p><p><em>This parameter was added in Cortex 2.6.3</em></p></td></tr><tr><td>includeDeprecatedPM</td><td><code>boolean</code></td><td>no</td><td><p>If <code>true</code> then deprecated performance metrics (i.e. Focus) will be exported. </p><p>The default value is <code>false</code>.<br><em>This parameter was added in Cortex 3.5.6</em></p></td></tr></tbody></table>

### Data streams

The parameter **streamTypes** must contain one or more values, chosen from this list: "EEG", "MOTION", "PM", "BP". If the **format** is "EDF" then only "EEG" and "MOTION" are available.

| Stream | Description                                                                                                                                                                                                                                                                      |
| ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| EEG    | <p>Export the raw EEG data, the contact quality of each EEG sensor, and the markers.<br>The license scope of the record must contain the scope "eeg".</p>                                                                                                                        |
| MOTION | Export the motion data.                                                                                                                                                                                                                                                          |
| PM     | <p>Export the results of the performance metric detection.</p><p>If the license scope of the record contains the scope "pm" then Cortex will export the high resolution performance metrics, at 2 hertz. Otherwise Cortex will export the low resolution data, at 0.1 hertz.</p> |
| MC     | Export the results of the mental command detection.                                                                                                                                                                                                                              |
| FE     | Export the results of the facial expression detection.                                                                                                                                                                                                                           |
| BP     | Export the band powers of each EEG sensor.                                                                                                                                                                                                                                       |

### Format and version

Depending on the parameters **format** and **version** Cortex will create different files.

#### Format EDF, no version&#x20;

This format is identical to the one used in Cortex 1.x

* 1 EDF file for the EEG and CQ data
* 1 EDF file for the motion data
* 1 JSON file for the markers
* 1 CSV file for the markers if the parameter **includeMarkerExtraInfos** is `true`

**Format EDFPLUS/BDFPLUS, no version** (available since Cortex version 3.7.5)

* 1 EDF+/BDF+ file for the EEG, CQ and Motion data
* 1 JSON file for the markers
* 1 CSV file for the markers if the parameter **includeMarkerExtraInfos** is true

#### Format CSV, version V1

This format is identical to the one used in Cortex 1.x

* 1 CSV file for the EEG and CQ data
* 1 CSV file for the band powers
* 1 CSV file for the motion data
* 1 CSV file for the performance metrics
* 1 JSON file for the markers
* 1 CSV file for the markers if the parameter **includeMarkerExtraInfos** is `true`

#### Format CSV, version V2

This format is the new format of Cortex 2.x

* 1 CSV file for all the data streams (EEG, CQ, band powers, motion, PM)
* 1 JSON file for the markers
* 1 CSV file for the markers if the parameter **includeMarkerExtraInfos** is `true`

## Result

The result is an object that includes these fields:

| Name    | Type               | Description                                                                                           |
| ------- | ------------------ | ----------------------------------------------------------------------------------------------------- |
| success | `array of objects` | For each record you successfully exported, this array contains an object that includes the record id. |
| failure | `array of objects` | For each record that couldn't be exported, this array contains an object that describes the error.    |

In case of success, you get an object with these fields:

| Name     | Type     | Description                                          |
| -------- | -------- | ---------------------------------------------------- |
| recordId | `string` | The id of the record that was successfully exported. |

In case of failure, you get an object with these fields:

| Name     | Type     | Description                                     |
| -------- | -------- | ----------------------------------------------- |
| recordId | `string` | The id of the record that couldn't be exported. |
| code     | `number` | The error code.                                 |
| message  | `string` | The error message.                              |

## Examples

### EDF

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

```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "exportRecord",
    "params": {
        "cortexToken": "xxx",
        "folder": "/tmp/edf",
        "format": "EDF",
        "recordIds": [
            "ec0ac33f-ad4e-48b1-bbc3-8502f5c49b62"
        ],
        "streamTypes": [
            "EEG",
            "MOTION"
        ]
    }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "failure": [],
        "success": [
            {
                "recordId": "ec0ac33f-ad4e-48b1-bbc3-8502f5c49b62"
            }
        ]
    }
}
```

{% endtab %}
{% endtabs %}

### CSV V1

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

```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "exportRecord",
    "params": {
        "cortexToken": "xxx",
        "folder": "/tmp/csv1",
        "format": "CSV",
        "recordIds": [
            "ec0ac33f-ad4e-48b1-bbc3-8502f5c49b62"
        ],
        "streamTypes": [
            "EEG",
            "MOTION",
            "PM",
            "BP"
        ],
        "version": "V1"
    }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "failure": [],
        "success": [
            {
                "recordId": "ec0ac33f-ad4e-48b1-bbc3-8502f5c49b62"
            }
        ]
    }
}
```

{% endtab %}
{% endtabs %}

### CSV V2

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

```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "exportRecord",
    "params": {
        "cortexToken": "xxx",
        "folder": "/tmp/csv2",
        "format": "CSV",
        "recordIds": [
            "ec0ac33f-ad4e-48b1-bbc3-8502f5c49b62"
        ],
        "streamTypes": [
            "EEG",
            "MOTION",
            "PM",
            "BP"
        ],
        "version": "V2"
    }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "failure": [],
        "success": [
            {
                "recordId": "ec0ac33f-ad4e-48b1-bbc3-8502f5c49b62"
            }
        ]
    }
}
```

{% endtab %}
{% endtabs %}
