> For the complete documentation index, see [llms.txt](https://docs.connectomesystem.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.connectomesystem.com/advance/data-api.md).

# DATA API

Our mission is to empower organizations by **democratizing access to data**. We believe that seamless and secure data access is the key to unlocking its full potential. Our Data API offers a user-friendly and secure gateway to your organization's data assets, ensuring that you can access and manage your data anytime, anywhere, without compromising on security.

## What you can do with Data API

* Read (with query or not)
* Write (with batch or not)
* Update
* Delete

## How to access Data API

1. Go to your collection&#x20;
2. Click Integration and select API
3. The description shows how you can access the API using different programming language.

<figure><img src="/files/IBdL4HC0v1D76joP1rKh" alt=""><figcaption></figcaption></figure>

## How to use API call

### Read Data with query

By default, the read API return all the data in the collection which can be inefficient and so we recommend you use **read with query**. Essentially, it allows you to **1)** filter, **2)** project (select the fields you want), **3)** sort, and **4)** limit (limit the amount of data returned). For example, imagine your collection looks like this in JSON format.

```json
[
    {
        "amount": 10,
        "title": "Movie ABC"
    }, 
    {
        "amount": 100,
        "title": "Movie BDD"
    }, 
    {
        "amount": 39,
        "title": "Movie XYZ"
    }
]
```

You can access your data using the `requests` library with Python. The syntax for filter is based on [MongoDB query language](https://www.mongodb.com/basics/examples).&#x20;

```python
# Import Library
import requests

# Request data using POST
data = requests.post(
    url='https://app.connectomesystem.com/collection/readwithquery/<read credential>/<collection id>',
    json={
        "query": {"amount":{"$gte":30}},
        "project": {"amount": 1, "title": 1},
        "sort": {"amount": 1},
        "limit": 10
        }
    )
    
```

### Update data with upsert

Allows to update the data in the specific field(s) and insert new data if the data in search do not exist.

#### Usage:

```python
# Import library
import requests

# Only the POST method allows in the update method.
resp = requests.post(
    url='https://app.connectomesystem.com/collection/updatewithupsert/<write credential/<collection id>',
    json={
        "search query": {
            "<field name 1>": "foo",
            "<field name 2>": "bar"
        },
        "data": {
            "<field name 3>": "baz"
        },
        "upsert": True
    }
)
```

<table><thead><tr><th width="187">Key</th><th>Description</th></tr></thead><tbody><tr><td>search query</td><td>Used to identify which data need to be updated. Field names are the fields that are defined in your collection.</td></tr><tr><td>data</td><td>The modification to apply</td></tr><tr><td>upsert</td><td>Boolean. Creates a new document if no documents match the <code>filter</code>. For more details see <a href="https://www.mongodb.com/docs/manual/reference/method/db.collection.update/#std-label-upsert-behavior">upsert behavior.</a> Default to <code>False</code>.</td></tr></tbody></table>

Noted that this function can return an error code due to no result found by the search query.

### Upload with batch data

Inserts multiple documents into a collection

#### Usage:

```python
# Import library
import requests

# Only the POST method allows in the upload method.
resp = requests.post(
    url='https://app.connectomesystem.com/collection/batchwrite/<write credential>/<collection id>',
    json={
        [
            {
                "field 1": "foo"
            },
            {
                "field 1": "bar"
            }
        ]
    }
)
```

This API parameter needs an array of data. The batch data will be inserted into the collection all at one time.

### Delete batch data with a query

Remove all the data that match the condition defined in the query.

#### Usage:

```python
# Import library
import requests

# Only the DELETE method allows in the remove method.
resp = requests.delete(
    url='https://app.connectomesystem.com/collection/batchdelete/<write credential>/<collection id>',
    json={
        'field 1': 'foo',
        'field 2': 'bar'
    }
)
```

The API parameter takes a query in JSON format. Any data will be removed if match the query.
