# Property Access

The Medable API affords developers the ability to access and update property data in flexible and convenient ways.

Although Property Selection can reduce the number of paths returned while maintaining the structure of the document. One way to do it

```javascript
// GET /accounts/5516ee2634d8d93428169c0e?paths[]=name.first

{
    "_id": "5516ee2634d8d93428169c0e",
    "name": {
        "first": "Jonas"
    },
    "object": "account"
}
```

A single property can also be directly accessed, resulting in a *result* response.

Even Simpler

```javascript
// GET /accounts/5516ee2634d8d93428169c0e/name/first

{
    "object": "result",
    "data": "Sarah Jones"
}
```

A property within a document array can be directly accessed, using its `_id` (`"551f34c8b8b206e835950b57"`). For example, retrieving the name of a custom role:

{% tabs %}
{% tab title="Custom Role" %}

```javascript
// GET /orgs/5516ee1b34d8d934281699e3/roles/551f34c8b8b206e835950b57/name

{
    "object": "result",
    "data": "Care Giver"
}
```

{% endtab %}
{% endtabs %}

Properties may be updated in the same way. The following are both valid ways to update the name of the above role:

{% tabs %}
{% tab title="PUT Example" %}

```javascript
// PUT /orgs/5516ee1b34d8d934281699e3

Request:
    {
        "roles": [{
            "_id": "551f34c8b8b206e835950b57",
            "name": "Third Party"
        }]
    }
Response:
    {
        "_id": "5516ee1b34d8d934281699e3",
        "object": "org",        
        "code": "example",        
        "roles": [{
            "_id": "551f3515b8b206e835950b59",
            "name": "Care Giver",
            "all": [],
            "include": []            
            },
            ...
        ],
        ...                
    }
```

{% endtab %}
{% endtabs %}

The above response includes the entire updated context.

{% tabs %}
{% tab title="PUT Example" %}

```javascript
// PUT /orgs/5516ee1b34d8d934281699e3/roles/551f34c8b8b206e835950b57/name

Request:
    "Third Party"
Response:
    {
        "object": "result",
        "data": "Third Party"
    }
```

{% endtab %}
{% endtabs %}

Property and Document arrays can be configured to allow overwrite, append-only, and/or pull. Arrays can also be configured to ensure unique values within the array, or in the case of a Document array, a property can have a validator that ensures it is unique within the rest of the parent array's documents.

* Appending items to an array using the API must be done using the `POST` method.
* Overwriting an array is done using `PUT`.
* Array elements can be directly access by index (`GET /orgs/5516ee1b34d8d934281699e3/roles/0`).
* Array elements cannot be updated by index.
* When removing elements from a document array, use the `_id` (`DELETE /orgs/5516ee1b34d8d934281699e3/roles/551f34c8b8b206e835950b57`)
* When removing elements from a primitive array, all matching values are removed (`DELETE /c_custom/c_tags/MyTag`)


---

# 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://docs.medable.com/cortex-api/querying/property-access.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.
