---
name: "getStatisticsConfig"
mode: "api"
versionRequirements:
  - { name: "@tuya-miniapp/cloud-api", version: "1.0.5" }
---

## getStatisticsConfig

> [VERSION] @tuya-miniapp/cloud-api >= 1.0.5

> 💡 This API is a cloud capability and requires authorization before use. For details on cloud capabilities, see the [documentation](/cn/miniapp/common/desc/tech-stack/api).
> Note: Currently, cloud capabilities are not available in the Developer Tools environment; you must package the app or debug on a real device.

### Description

Retrieve the statistics configuration and the DPs enabled for Smart Metering, along with their settings.

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `data` | `IDevId` | Yes | Request body |

### Return Value

Type: `Promise<IStatisticsConfig[]>`

IStatisticsConfig[] (see type definitions and the minituya return value table for field meanings)

##### IStatisticsConfig

| Property | Type | Description |
| --- | --- | --- |
| `algorithmType` | `"sum" \| "avg" \| "minux" \| "max" \| "min" \| "count" \| "recent"` | Statistic types Aggregation algorithms, consistent with the minituya 'Statistics Types' description. - `sum`: Sum of reported values within the period; for cumulative metrics. - `minux`: Current period maximum minus previous period maximum; represents increment/usage (historical spelling, not `minus`). - `avg`: Sum divided by the number of reports; yields the average. - `min` / `max`: Minimum / maximum within the period. - `count`: Number of reports within the period. - `recent`: Most recent value. |
| `dpId` | `number \| string` | DP IDs with statistics enabled |
| `productId` | `string` | Product ID |
| `statisticInterval` | `number` | Statistics interval (aligned with cloud enumerations): `1` day, `2` hour, `4` month, `16` indicates 15-minute granularity. |
| `storageDuration` | `number` | Retention days in the cloud for this statistics type |

### Referenced Types

##### `type` IDevId

Request body containing only the device ID (e.g., `getStatisticsConfig`, `resetStatistics`).

| Property | Type | Description |
| --- | --- | --- |
| `devId` | `string` | Device ID |


### Examples

#### Request example

```typescript
import { getStatisticsConfig } from '@tuya-miniapp/cloud-api';

getStatisticsConfig({
  devId: 'vdevo166789063330437',
})
  .then((response) => {
    console.log(response);
  })
  .catch();
```

#### Response example

```json
[
  {
    "storageDuration": 365,
    "productId": "lcrxzqjqojafatrv",
    "dpId": 18,
    "statisticInterval": 1,
    "algorithmType": "avg"
  },
  {
    "storageDuration": 365,
    "productId": "lcrxzqjqojafatrv",
    "dpId": 1,
    "statisticInterval": 1,
    "algorithmType": "count"
  },
  {
    "storageDuration": 7,
    "productId": "lcrxzqjqojafatrv",
    "dpId": 1,
    "statisticInterval": 2,
    "algorithmType": "count"
  }
]
```
