# Data Sessions

{% hint style="info" %}
This endpoint in only applicable for **BACE GO**. Not sure which device you are working with? Find out [here](https://docs.bace-iot.com/reference/powering-iot-connectivity-modules).
{% endhint %}

Whenever a **BACE Go** is turned on, a Data Session is created automatically in the BACE cloud. The Data Session is automatically closed when the device is turned off.

![](https://2186022299-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQAP1rE2NAOVH04TQmlau%2Fuploads%2FyE7OGR46poA34keOuKPk%2Fimage.png?alt=media\&token=9d33a78d-290e-49ee-a30d-c17daf5d472d)

The BACE API for Data Sessions allows you to:

* Get information about the Data Session
* Get information about the device reporting data
* Get all data associated with Data Session

To start getting Data Sessions data from the BACE API, you must have:

* An active User account
* A physical or virtual device (able to start/stop Data Session) provisioned and related to your project
* (Optionally) a peripheral or sensor connected to your BACE device

## How to get Data Sessions Data?

To retrieve data from a data session, two request are required:

* List all Data Sessions
* Get specific data from session
* Download full session in CSV file

### List all Data Sessions

To get list of all Data Sessions in the system available for you, you should make a GET request

<mark style="color:blue;">`GET`</mark>`https://`dashboard.bace-iot.com`/api/v2/data-session?sort=-star`

In our example we will sort Data Sessions on start time descending, such that the latest Data Sessions that was started is in the beginning of the list.

```json
{
      "items": [
          {
              "id_data_session": "86d70a1b-...",
              "id_group": "4c1c81ca-...",
              "id_person": null,
              "label": "BACE Go XXX 2022-03-30 14:04",
              "start": 1648641893,
              "end": 1648643067,
              "created_at": 1648641897,
              "created_by": null,
              "updated_at": 1648643384,
              "updated_by": null,
              "archived_at": null,
              "datapoint_count": 10,
              "isIngestionFinished": true,
              "isArchived": false,
              "_links": {
                  "self": {
                      "href": "https://dashboard.bace-iot.com/api/v2/data-session/view?id=86d70a1b-..."
                  },
                  "index": {
                      "href": "https://dashboard.bace-iot.com/api/v2/data-session/index"
                  }
              }
          },
          ...
      ]
      "_links": {
          "self": {
              "href": "https://dashboard.bace-iot.com/api/v2/data-session?sort=-start&page=1"
          },
          "first": {
              "href": "https://dashboard.bace-iot.com/api/v2/data-session?sort=-start&page=1"
          },
          "last": {
              "href": "https://dashboard.bace-iot.com/api/v2/data-session?sort=-start&page=274"
          },
          "next": {
              "href": "https://dashboard.bace-iot.com/api/v2/data-session?sort=-start&page=2"
          }
      },
      "_meta": {
          "totalCount": 5474,
          "pageCount": 274,
          "currentPage": 1,
          "perPage": 20
      },
      "expand": [
          "datatypes",
          "datatypesFilter",
          "creator",
          "updater",
          "physicalDevicesFilter",
          "physicalDevices",
          "fromDevice",
          "group",
          "dataIds"
      ],
      "labels": {
          "group.label": "Group",
          "person.label": "Person",
          "person.objectLink": "Person",
          "sourceDevicesString": "Source Devices",
          "datatypesString": "Datatypes",
          "ingestionStatusString": "Ingestion",
          "archivingStatusString": "Archived"
      }
    }

```

In the response you will get basic information about all Data Sessions. You have access to the following fields:

| Field               | Description                                                                                                                                        |
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| id\_data\_session   | UUID of the Data session                                                                                                                           |
| id\_group           | UUID of the Group device is in. To get more information use: expand=group                                                                          |
| id\_person          | UUID of the Person related to the Datasession                                                                                                      |
| label               | Descriptive label for the datasession                                                                                                              |
| start               | Data session start timestamp in seconds                                                                                                            |
| end                 | Data session end timestamp in seconds. null - if Data session is active and not stopped                                                            |
| created\_at         | Timestamp in seconds, when Data sessions record have been created                                                                                  |
| created\_by         | UUID of the User, who have created Data session. For Data session started from the device - null. To get more information use: expand=creator      |
| updated\_at         | Timestamp in seconds, when Data sessions record have been last updated                                                                             |
| updated\_by         | UUID of the User, who have last updated Data session. For Data session updated from the device - null. To get more information use: expand=updater |
| archived\_at        | Timestamp in seconds, when Data session have been archived                                                                                         |
| datapoint\_count    | Total datapoint count in the Data session                                                                                                          |
| isIngestionFinished | Boolean describing data ingestion process                                                                                                          |
| isArchived          | Boolean describing, if archiving of Data session have been finished                                                                                |

### Get data from Data Session

To get specific data associated with a Data Session. You should make a GET request from the `data-downsampled` endpoint, specifiying the session ID.

<mark style="color:blue;">`GET`</mark>` ``https://dashboard.bace-iot.com/api/v2/data-downsampled?filter[id_data_session]=ID_DATA_SESSION`

Example response:

```json
{
  "items": [
      {
          "id_container_data_latest": "c1dafb46-...",
          "id_group": "4c1c81ca-...",
          "datatype": 5205,
          "source_device": "6b88b4df-...",
          "timestamp_seconds": 1648641939.995,
          "min_val": 3.95,
          "max_val": 3.95,
          "avg_val": 3.95,
          "count_val": 1
      },
      {
          "id_container_data_latest": "c1dafb46-...",
          "id_group": "4c1c81ca-...",
          "datatype": 5205,
          "source_device": "6b88b4df-...",
          "timestamp_seconds": 1648642239.995,
          "min_val": 3.94,
          "max_val": 3.94,
          "avg_val": 3.94,
          "count_val": 1
      },
      ...
  ],
  "_links": {
      "self": {
          "href": "https://dashboard.bace-iot.com/api/v2/data-downsampled?filter%5Bid_data_session%5D=86d70a1b-...&page=1"
      },
      "first": {
          "href": "https://dashboard.bace-iot.com/api/v2/data-downsampled?filter%5Bid_data_session%5D=86d70a1b-...&page=1"
      },
      "last": {
          "href": "https://dashboard.bace-iot.com/api/v2/data-downsampled?filter%5Bid_data_session%5D=86d70a1b-...&page=1"
      }
  },
  "_meta": {
      "totalCount": 10,
      "pageCount": 1,
      "currentPage": 1,
      "perPage": 500
  }
}
```

| Field                       | Description                                                             |
| --------------------------- | ----------------------------------------------------------------------- |
| id\_container\_data\_latest | UUID which describes combination of Group, Physical Device and Datatype |
| id\_group                   | UUID of Group                                                           |
| datatype                    | Datatype of stored data                                                 |
| source\_device              | UUID of Physical Device, BACE Cloud have received data from             |
| timestamp\_seconds          | Timestamp in seconds                                                    |
| min\_val                    | Minimal value                                                           |
| max\_val                    | Maximal value                                                           |
| avg\_val                    | Average value                                                           |
| count\_val                  | Count of downsampled samples                                            |

If data is downsampled, the field count\_val is greater than 1. In this case, you can also request data between 2 timestamps to get data with a higher resolution, i.e. more datapoints.

More information about [downsampling mechanism ](https://docs.bace-iot.com/accessing-data#downsampling-mechanism)and how to use [data-downsampled endpoint](https://docs.bace-iot.com/accessing-data#using-downsampled_data-endpoint)

### Download data in .csv file

To download the complete Data Session in a CSV file, you should make GET request from the download-csv endpoint.

<mark style="color:blue;">`GET`</mark>` ``https://dashboard.bace-iot.com/api/v2/data-session/ID_DATA_SESSION/download-csv`
