# Data Export API

Browsee automatically collects data about all the sessions that happen on your site. In case you have any of the following requirements, you can utilize our data export API

* Saving data beyond Browsee's data retention limit
* Creating or generating reports beyond the scope of Browsee's analytics.
* Augment your own data with data collected from Browsee.

In order to get started, please generate a secret key and read about the data export APIs below.

## Generate Your Secret API Key

Go to Your [Accounts or Settings Page](https://browsee.io/app/settings?view=integrations) in Browsee and generate a secret key.

## Exporting Data

### Session Export API

## export/sessions

<mark style="color:green;">`POST`</mark> `https://api.browsee.io/api/v1/export/sessions`

An API to export a list of sessions&#x20;

#### Request Body

| Name      | Type    | Description                                                                                                                                               |
| --------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| apiKey    | string  | Your project's API Key                                                                                                                                    |
| secretKey | string  | Secret key generated above.                                                                                                                               |
| start     | integer | Timestamp of the starting time. Use Unix seconds (seconds since epoch). Defaults to 24 hours before now.                                                  |
| end       | integer | Timestamp of the ending time. Use Unix seconds (seconds since epoch). Defaults to Now.                                                                    |
| from      | integer | The offset in the result set. For e.g. if the result has total of 1000 entries and you want to fetch the last 100, then this would be 900. Defaults to 0. |
| limit     | integer | The number of results to get. Default to 100. The maximum value of this is also 100.                                                                      |
| segmentId | string  | This is the ID of a segment you created. This is the ID in the URL when you view a segment's analytics.                                                   |
| options   | object  | Additional options to be provided for data export like which fields to select.                                                                            |

{% tabs %}
{% tab title="200 In case of successful execution of request" %}

```
{
    "status": "success",
    "exports": {
         // Total sessions satisfying the query
        "total": N,
         // Session index upto which result is being provided  
        "to": i,
        "data": [
            {
            // Session data ...
            }
        ]
    }
}
```

{% endtab %}

{% tab title="400 In case if any of the required parameters is not provided or if any of the optional parameters does not follow the right format." %}

```
{
    "status": "failure",
    "message": {
        "error": "API Key missing."
    }
}
```

{% endtab %}

{% tab title="401 If Secret key does not match the account. " %}

```
{
    "status": "unauthorized",
    "message": {
        "error": "Secret Key invalid."
    }
}
```

{% endtab %}
{% endtabs %}

### Using the session export API

Session export API gives you all the details related to users and sessions either without any constraint or based on an existing circle in your account. Please note the following points.

* It only supports `POST` method
* This is a pagination based API. The page size by default is 100 sessions.
* In your first request, you will get the total number of results and the offset index up to which sessions have been exported. You can send more requests with changing the offset parameter (`from`) to get subsequent sessions.
* As an example, the first request will return documents starting from 0 upto 100. In the next request you can send `from` to be 100 and this time you will get documents from 100 to 200 and so on.
* Its rate limited to one open request. You must wait for the response from one request before initiating another request.

### Getting the sessions for a Segment

You can send an optional parameter: **`segmentId`** to get the sessions for that segment. To get the segment Id, you can go to the [list of Segments](https://browsee.io/app/circleslist) and click on **View Analytics** for the desired segment.&#x20;

![](/files/-MD3njQgBLffmnetOxoX)

This segment's ID is the ID in the URL of the analytics page as shown

![Segment ID in URL](/files/-MD3nr9oacSQ5e5cDcRF)

### Getting only a subset of fields

To limit the number of fields and data provided, you can provide additional parameters like below to give the list of fields that you need.

```
{
  apiKey: <API Key>,
  secretKey: <Secret Key>,
  options: {
    select: ['userId', 'urls', 'duration']
  }
}
```

Here is a list of fields that you can provide in `select:`

* `userId`: User ID, as provided by `identify` call&#x20;
* `duration` : Duration in milliseconds of the session.
* `inactiveTime` : Duration during which user was inactive during the session (milliseconds).
* `activeTime` : Difference between duration and inactiveTime (milliseconds).
* `urls`: URL's visited in the session
* `timestamp`: Unix timestamp in milliseconds since the epoch of the start of the session
* `pageCount`: Number of pages visited
* `eventCount`: Number of events found
* `name`: Name if provided in `identify` call
* `email`: Email if provided in `identify` call
* `tags`: Tags if provided in `identify` call
* `landingPage`: Landing Page of session
* `utm_source/utm_medium/utm_campaign/utm_term/utm_content`: UTM Parameters
* `browser`: User's Browser
* `os`: Operating System
* `device`: User's device
* `isMobile`: If the device is considered to be Mobile
* `ip`: IP from which session originated
* `city`: City detected (based on IP)
* `country`: Country detected (based on IP)
* `domain`: Domain from which session was recorded
* `referrer`: Referrer of the session (only the domain)

### Examples

* [NodeJS Example](https://gist.github.com/mathurs/991a5507f533aa9e36f7608f7316d056)
* [Python Example](https://gist.github.com/mathurs/0a4aa2bcbef36724866675fbcf441579)
* Please write to us at <contact@heroteck.com> in case you need more examples.


---

# 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.browsee.io/integration/api-calls/data-export-api.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.
