> ## Documentation Index
> Fetch the complete documentation index at: https://compass.docs.sunnyscoach.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Incidents Trend

> Retrieve the daily trend of incidents (tickets) within a specified date range.

# Incidents Trend

Retrieve the trend of incidents for a given date range.\
This endpoint returns:

* `labels`: an array of dates in the interval
* `series`: number of incidents for each corresponding date

## Endpoint

`GET /hubspot/stats/incidents-trend/:startDate/:endDate`

### URL Parameters

| Parameter   | Type   | Required | Description                          |
| ----------- | ------ | -------- | ------------------------------------ |
| `startDate` | string | ✅        | Start date of the range (YYYY-MM-DD) |
| `endDate`   | string | ✅        | End date of the range (YYYY-MM-DD)   |

### Request Headers

| Header          | Value            | Description               |
| --------------- | ---------------- | ------------------------- |
| `Authorization` | `Bearer <token>` | User authentication token |

> **Note:** No request body is required.

## Response

### Success Response (HTTP 200)

```json theme={null}
{
  "message": "",
  "data": {
    "labels": ["2025-11-01", "2025-11-02", "2025-11-03"],
    "series": [5, 3, 7]
  }
}
```

* `labels`: Dates between `startDate` and `endDate`
* `series`: Number of incidents created on each date

### Error Response (HTTP 400–500)

```json theme={null}
{
  "message": "Invalid params",
  "data": {}
}
```

> Any non-200 status code indicates an error.

## Authentication

This endpoint requires user authentication via `Authorization: Bearer <token>`.\
No user data should be sent — it is populated internally.

## Example Request (cURL)

```bash theme={null}
curl -X GET "https://yourdomain.com/hubspot/stats/incidents-trend/2025-11-01/2025-11-07" \
-H "Authorization: Bearer YOUR_TOKEN"
```

## Example Request (JavaScript - fetch)

```javascript theme={null}
const response = await fetch(
  "/hubspot/stats/incidents-trend/2025-11-01/2025-11-07",
  {
    method: "GET",
    headers: {
      "Authorization": "Bearer YOUR_TOKEN"
    }
  }
);

const data = await response.json();
console.log(data);
```

## Notes

* Dates must follow `YYYY-MM-DD` format.
* Dates without incidents will appear in `labels` with `0` count in `series`.
* Trend calculation is computed server-side using the ticket creation date.
