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

## getStatisticsRangMonth

> [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

Get device statistics over a date range with month as the interval.

### Parameters

`Params`

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

### Return Value

Type: `Promise<IStatisticsData>`

IStatisticsData (keys are months, etc.; see the response example in the docs)

### Referenced Types

##### `type` IGetStatisticsRangMonth

Range statistics by month: common fields + start/end month.

```typescript
export type IGetStatisticsRangMonth = ICommonGetStatisticsRang & StartEndMonth;
```

##### `type` ICommonGetStatisticsRang

Common fields for range statistics/export requests (combined with `IDate`, `IStartEndDay`, `StartEndMonth` to form concrete input types).

| Property | Type | Description |
| --- | --- | --- |
| `devId` | `string` | Device ID |
| `dpId` | `number \| string` | Data point ID (DP) to be aggregated |
| `type` | `"sum" \| "avg" \| "minux" \| "max" \| "min" \| "count" \| "recent"` | Statistic type; if omitted, each API has a default in `index` (mostly `sum`). Aggregation algorithm, aligned with minituya 'Statistic Type Description'. - `sum`: Sum of values reported within the interval; suitable for cumulative metrics. - `minux`: Current interval maximum minus previous interval maximum, representing increment/consumption (historical spelling, not `minus`). - `avg`: Sum divided by the number of reports to obtain the average. - `min` / `max`: Minimum / maximum within the interval. - `count`: Number of reports within the interval. - `recent`: Most recent statistic value. |
| `auto` | `number` | Data filling strategy, consistent with the cloud-side agreement; default is `0` for all APIs. Refer to the IoT platform’s Smart Metering/Open API specs for the exact enum values. |
| `keepScalaPoint` | `boolean` | When `true`, decimal places align with the device DP `scale`; default is `false`. |

##### `type` StartEndMonth

A month range at month granularity (for `getStatisticsRangMonth`/`exportStatisticsMonth`).

| Property | Type | Description |
| --- | --- | --- |
| `startMonth` | `string` | Start month, `yyyyMM`, e.g., `202304` |
| `endMonth` | `string` | End month, `yyyyMM` |


### Examples

#### Request example

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

getStatisticsRangMonth({
  devId: 'vdevo161733425146241',
  dpId: '18',
  startMonth: '202304',
  endMonth: '202305',
  type: 'avg',
})
  .then((response) => {
    console.log(response);
  })
  .catch();
```

#### Response example

```json
{
  "202304": "0",
  "202305": "24.00"
}
```
