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

## exportStatisticsMonth

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

Export the device’s statistics for the past month, with month as the interval.

### Parameters

`Params`

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

### Return Value

Type: `Promise<boolean>`

true indicates the export request succeeded (the sample response in the docs is true)

### Referenced Types

##### `type` IGetStatisticsExportMonth

Export by month: common export fields + start/end month.

```typescript
export type IGetStatisticsExportMonth = ICommonGetStatisticsExport & StartEndMonth;
```

##### `type` ICommonGetStatisticsExport

Common request fields for export APIs (hour/day/month).
`dpExcelQuery` accepts `IDpExcelQuery` or an equivalent string produced by `JSON.stringify`.

| Property | Type | Description |
| --- | --- | --- |
| `email` | `string` | Email address to receive the exported file |
| `lang` | `string` | Locale code, e.g., `cn`, `en`; default `en` |
| `devId` | `string` | Device ID |
| `dpExcelQuery` | `IDpExcelQuery[] \| string` | Export column definitions; when an array of objects is provided, the SDK will serialize it to a JSON string before reporting. Example array (conceptual): `[{"dpId":"101","name":"华氏度转摄氏度","handler":"temperatureF2C"},{"dpId":"101","name":"摄氏度转华氏度","handler":"temperatureC2F"}]` Note: In minituya documentation this column is named `title`; the example and SDK type use `name`. |
| `auto` | `number` | Data filling strategy, default `0` (same meaning as in range queries). |
| `keepScalaPoint` | `boolean` | Whether decimal places align with `scale`; default `false` (note the spelling `keepScalaPoint`) |
| `type` | `"sum" \| "avg" \| "minux" \| "max" \| "min" \| "count" \| "recent"` | Statistic type, default `sum` - `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. |
| `title` | `string` | Email subject; if omitted, the SDK default title is used. |

##### `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` |

##### `type` IDpExcelQuery

Column configuration in the exported Excel email; the object array is serialized with `JSON.stringify` before the request (see `exportStatistics*`).

| Property | Type | Description |
| --- | --- | --- |
| `dpId` | `number \| string` | DP ID for the column |
| `name` | `string` | Column header for Excel export |
| `handler` | `string` | Column data conversion; supports `temperatureF2C` (Fahrenheit to Celsius), `temperatureC2F` (Celsius to Fahrenheit), `cubicMeterToGallon` (cubic meters to gallons), and `gallonToCubicMeter` (gallons to cubic meters). |


### Examples

#### Request example

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

exportStatisticsMonth({
  devId: 'vdevo161733425146241',
  email: 'xxxdemo@*.com',
  dpExcelQuery: [{ dpId: 18, name: 'Excel data column title' }],
  startMonth: '202304',
  endMonth: '202305',
  type: 'avg',
  lang: 'cn',
  title: 'This is a title',
})
  .then((response) => {
    console.log(response);
  })
  .catch();
```

#### Response example

```json
true
```
