# setupProfile

This method is to manage the training profiles of the user.

You create, rename or delete a profile. You can load and unload a profile for a headset if the EEG channels of this headset is supported by this training profile. And you can save a profile after the user completed a [training](training), or after you changed the [attributes](../advanced-bci) of the profile.

Before you load or unload a profile, you can call [getCurrentProfile](getcurrentprofile) to know if a profile is currently loaded, and if it was loaded by your application.

## Parameters

| Name           | Type     | Required                         | Description                                                                                             |
| -------------- | -------- | -------------------------------- | ------------------------------------------------------------------------------------------------------- |
| cortexToken    | `string` | yes                              | A token returned by [authorize](../authentication/authorize).                                           |
| status         | `string` | yes                              | Must be "create", "load", "unload", "save", "rename" or "delete".                                       |
| profile        | `string` | yes                              | The name of the profile.                                                                                |
| headset        | `string` | yes or no, depending on "status" | A headset id returned by [queryHeadsets](../headset/queryheadsets).                                     |
| newProfileName | `string` | no                               | If the **status** is "rename", then you must set this parameter, and it is the new name of the profile. |

Depending on the **status**, this method has different effects, and uses different parameters.

### Status create

Create a new profile. It can be an empty profile, or a copy of a loaded profile.

| Name    | Type     | Required | Description                                                                                                                         |
| ------- | -------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| profile | `string` | yes      | The name of the new profile. It must be unique for the user. Use [queryProfile](queryprofile) to check if a name is already in use. |
| headset | `string` | yes      | create a copy of the profile currently loaded for this headset.                                                                     |

### Status load

Load an existing profile for a specific headset. If a profile is already loaded, then you must unload it first.

| Name    | Type     | Required | Description                                   |
| ------- | -------- | -------- | --------------------------------------------- |
| profile | `string` | yes      | The name of the profile to load.              |
| headset | `string` | yes      | The id of the headset to load the profile to. |

### Status unload

Unload the profile of a specific headset. After the unload, this headset will use a default empty profile. You should set the parameter **profile** to an empty string. You cannot unload a profile that was loaded by another application.

| Name    | Type     | Required | Description                                                   |
| ------- | -------- | -------- | ------------------------------------------------------------- |
| headset | `string` | yes      | The id of the headset to unload the profile.                  |
| profile | `string` | yes      | Cortex will ignore this parameter. Should be an empty string. |

### Status save

Save the profile used by a headset. You can save it with a new name, so it creates a new profile. Or you can save it with the same name, ie the name you used to load it. You cannot save a profile that was loaded by another application.

| Name    | Type     | Required | Description                                                                                                                                                                                                                                  |
| ------- | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| headset | `string` | yes      | The profile used by this headset will be saved.                                                                                                                                                                                              |
| profile | `string` | yes      | <p>The name of the profile.</p><p>If no profile with that name exists, then the method creates a new profile.</p><p>If it is the name of the profile that was previously loaded to this headset, then the method saves to this profile. </p> |

### Status rename

Rename an existing profile.

| Name           | Type     | Required | Description                                 |
| -------------- | -------- | -------- | ------------------------------------------- |
| profile        | `string` | yes      | The name of the profile you want to rename. |
| newProfileName | `string` | yes      | The new name of the profile.                |

### Status delete

Delete an existing profile. If this profile is loaded for a headset, then it is automatically unloaded. You cannot delete a profile that is currently loaded by another application.

| Name    | Type     | Required | Description                                 |
| ------- | -------- | -------- | ------------------------------------------- |
| profile | `string` | yes      | The name of the profile you want to delete. |

## Result

The result is an object containing these fields:

| Name    | Type     | Description                              |
| ------- | -------- | ---------------------------------------- |
| action  | `string` | The **status** you used in the request.  |
| name    | `string` | The **profile** you used in the request. |
| message | `string` | A success message.                       |

## Examples

### Create a new empty profile

{% tabs %}
{% tab title="Request" %}
```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "setupProfile",
    "params": {
        "cortexToken": "xxx",
        "profile": "cortex-v2-example",
        "status": "create"
    }
}
```
{% endtab %}

{% tab title="Response" %}
```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "action": "create",
        "message": "...",
        "name": "cortex-v2-example"
    }
}
```
{% endtab %}
{% endtabs %}

### Load a profile for a headset

{% tabs %}
{% tab title="Request" %}
```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "setupProfile",
    "params": {
        "cortexToken": "xxx",
        "headset": "EPOCPLUS-12341234",
        "profile": "cortex-v2-example",
        "status": "load"
    }
}
```
{% endtab %}

{% tab title="Response" %}
```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "action": "load",
        "message": "The profile is loaded successfully",
        "name": "cortex-v2-example"
    }
}
```
{% endtab %}
{% endtabs %}

### Save a profile

{% tabs %}
{% tab title="Request" %}
```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "setupProfile",
    "params": {
        "cortexToken": "xxx",
        "headset": "EPOCPLUS-12341234",
        "profile": "cortex-v2-example",
        "status": "save"
    }
}
```
{% endtab %}

{% tab title="Response" %}
```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "action": "save",
        "message": "The profile is saved successfully",
        "name": "cortex-v2-example"
    }
}
```
{% endtab %}
{% endtabs %}
