# API Data Export

### Overview

This guide provides instructions for synchronizing analytics data using the MIDA Sessions Replay & Heatmap API, including in-app configuration for sync frequency and API key management, as well as the cURL request format.

### Prerequisites

* **API Endpoint**: `https://mida-session-recording-replay.bsscommerce.com/apiv1/analytics/sync`
  * **API Key**: Generated and named via the in-app API Configuration Screen.
* **Tool**: cURL or any HTTP client for making POST requests.
* **Access**: Admin access to the MIDA application for configuration.

![API Data export settings](https://2268112615-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEBoONmhNHT36hqyG5yXC%2Fuploads%2Fgit-blob-fb913187ab6c43b9837799089ece8886d20e5056%2FAPI-setting.png?alt=media)

### In-App Configuration

#### API Configuration Screen

1. **Navigate to Settings**:
   * Go to the "Analytics API Data Export" section in the MIDA application.
2. **Enable API**:
   * Toggle **API Status** to \[Activated].
3. **Generate API Key**:
   * Click \[Generate API Key].
   * Copy the generated key using the \[Copy Button] for use in API requests.
4. **Set Sync Frequency**:
   * Select from the **Data Sync Frequency** dropdown:
     * **Daily**: Syncs data from the previous day.
     * **Weekly**: Syncs data from the previous week.
5. **(Optional) Configure Email Notifications**:
   * Choose "Notify me when data sync is successful" in **Receive email Notifications.**
   * Enter **Recipient** (default as store email).
6. **Save Settings**:
   * Click \[Save] on the top barto apply changes.

![Save Settings](https://2268112615-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEBoONmhNHT36hqyG5yXC%2Fuploads%2Fgit-blob-1a3a962fda21ab4f6c55026dbd617ad389a40c76%2FSave.png?alt=media)

### API Request

To synchronize analytics data, use the following cURL command, ensuring the frequency matches the in-app setting:

```bash
curl -X POST \\
  <https://mida-session-recording-replay.bsscommerce.com/apiv1/analytics/sync> \\
  -H 'Content-Type: application/json' \\
  -H 'x-mida-secret-key: {your_api_key}' \\
```

#### Parameters

* **Method**: POST
* **Headers**:
  * `Content-Type: application/json`
  * `Mida-api-key: {your_api_key}` (Replace `{your_api_key}` with your generated API key in **API secret key**)

#### Example

```bash
curl -X POST \\
  <https://mida-session-recording-replay.bsscommerce.com/apiv1/analytics/sync> \\
  -H 'Content-Type: application/json' \\
  -H 'x-mida-secret-key: abc123xyz789' \\
```

### Response

* **Success**: Returns synced data (e.g., Total Visitors, Total Sessions, Successful Orders, etc.).
* **Failure**: Returns error message (e.g., "Invalid API key" or "Sync failed").

### Monitoring

* **Email Notifications**:
  * **Success**:
    * Subject: "\[Analytics Sync] Success - \[YYYY-MM-DD HH:mm]"
    * Content: Timestamp, Status.
  * **Failure**:
    * Subject: "\[Analytics Sync] Failed - \[YYYY-MM-DD HH:mm]"
    * Content: Timestamp, Status.

### Re-generate API secret key

To remove an old API key, click "Regenerate secret key" and regenerate a new one when needed:

<figure><img src="https://2268112615-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEBoONmhNHT36hqyG5yXC%2Fuploads%2Fgit-blob-c20c83652e80a985063cb14cb469ed449f8fdd66%2Fimage%20(341).png?alt=media" alt=""><figcaption><p>Regenerate secret key</p></figcaption></figure>

### Notes

* Keep the API key secure and regenerate if compromised.
* For support, contact the MIDA team via the provided support channel.

If you have any questions, feel free to contact us via **Crisp Chat** or email us at [support@mida-app.io](mailto:support@mida-app.io?subject=%5BMIDA%20Support%5D%20Question%20about%20Fraud%20Score\&body=Hi%20MIDA%20Team%2C%0A%0AI%20have%20a%20question%20about%20the%20Fraud%20Score%20feature.%20Please%20assist%20me%20with%20the%20following%3A%0A%0A-%20Shop%20URL%3A%20%0A-%20Issue%20details%3A%20%0A%0AThank%20you!%0A%0A%2D%20Your%20Name).
