# createSubject

This method is to create a new subject. Then you can associate the subject to a record when you call [createRecord](/cortex-api/records/createrecord.md).

*This method was added in Cortex 2.1*

## Parameters

| Name        | Type               | Required | Description                                                                                                               |
| ----------- | ------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------- |
| cortexToken | `string`           | yes      | A token returned by [authorize](/cortex-api/authentication/authorize.md).                                                 |
| subjectName | `string`           | yes      | The name of the subject. Must be 30 characters or less.                                                                   |
| dateOfBirth | `string`           | no       | The date of birth of the subject. The format must be "YYYY-MM-DD", e.g. "1980-12-25".                                     |
| sex         | `string`           | no       | Must be "M", "F" or "U". These letters stands for male, female and unknown respectively.                                  |
| countryCode | `string`           | no       | The [Alpha-2 ISO code](https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes) of the country the subject lives in. |
| state       | `string`           | no       | The state the subject lives in.                                                                                           |
| city        | `string`           | no       | The city the subject lives in.                                                                                            |
| attributes  | `array of objects` | no       | A list of demographic attribute objects. See [Subject object](/cortex-api/subjects/subject-object.md).                    |

## Result

The result is a [subject object](/cortex-api/subjects/subject-object.md) representing the new subject.

## Examples

Create a subject with only his name.

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

```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "createSubject",
    "params": {
        "cortexToken": "xxx",
        "subjectName": "Bob Smith"
    }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "attributes": [],
        "city": "",
        "countryCode": "",
        "countryName": "",
        "dateOfBirth": "",
        "experimentsCount": 0,
        "modifiedDatetime": "2019-07-01T11:41:25.270+07:00",
        "sex": "U",
        "state": "",
        "subjectName": "Bob Smith"
    }
}
```

{% endtab %}
{% endtabs %}

Create a subject with more information.

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

```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "createSubject",
    "params": {
        "cortexToken": "xxx",
        "subjectName": "Alice Smith",
        "city": "London",
        "countryCode": "GB",
        "dateOfBirth": "1980-12-25",
        "sex": "F",
        "attributes": [
            {
                "name": "Handedness",
                "value": "Left"
            },
            {
                "name": "Education",
                "value": "Master's degree"
            }
        ]
    }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "attributes": [
            {
                "name": "Handedness",
                "value": "Left"
            },
            {
                "name": "Education",
                "value": "Master's degree"
            }
        ],
        "city": "London",
        "countryCode": "GB",
        "countryName": "",
        "dateOfBirth": "1980-12-25",
        "experimentsCount": 0,
        "modifiedDatetime": "2019-07-01T11:23:11.644+07:00",
        "sex": "F",
        "state": "",
        "subjectName": "Alice Smith"
    }
}
```

{% 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/subjects/createsubject.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.
