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

## getAnalyticsLogsPublishLog

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

### Description

Get issued-log history within a time range

### Parameters

`Params`

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

### Return Value

Type: `Promise<GetAnalyticsLogsResult>`

Includes dps (DP result list), hasNext, and total; each dps element is DpResult (in the issued-log scenario, nickName and userName are included).

##### GetAnalyticsLogsResult

| Property | Type | Description |
| --- | --- | --- |
| `dps` | `DpResult[]` | Device DP data collection |
| `hasNext` | `boolean` | Whether there is a next page of data |
| `total` | `number` | Total record count |

### Referenced Types

##### `type` GetAnalyticsLogsParams

Common request parameters for send/report log queries (fields align with the minituya parameter table; SchemaDoc extracts descriptions from properties of this type).

| Property | Type | Description |
| --- | --- | --- |
| `devId` | `string` | Device ID |
| `dpIds` | `string` | DP IDs. Multiple DPs are supported, separated by commas. |
| `dpValues` | `string` | Query the value of the specified DP. Takes effect only when dpIds contains a single item; queries with multiple dpIds are not supported. Raw-type DPs are not supported. Currently effective only for the free edition of device logs. |
| `offset` | `number` | When querying, return results starting after the specified sequence (offset starts at 0). |
| `limit` | `number` | Maximum per page; offset + limit must be less than or equal to 1000. |
| `startTime` | `string` | Device report time: query start time in milliseconds. If empty, defaults to the timestamp 7 days ago. |
| `endTime` | `string` | Device report time: query end time in milliseconds. If empty, defaults to the current timestamp. |
| `sortType` | `string` | DESC for descending or ASC for ascending; default is DESC. |
| `queryType` | `string` | `0`: Automatically switch the query data source based on the product ID associated with the device ID. `1`: Query the free device log data source. `2`: Query the paid device log data source.  If you haven’t purchased the paid log, this parameter can be omitted |

##### `type` DpResult

Single DP query result. The downlink and uplink documents differ in the field set and the shape of `dpId` (including discrepancies between response examples and parameter tables); this complements the API `@returns` and serves as a type-level description.

| Property | Type | Description |
| --- | --- | --- |
| `dpId` | `number \| string` | `number` is consistent with the documentation table; the report log response example also contains a string combining multiple DPs |
| `value` | `any` | DP value |
| `timeStamp` | `number` | Timestamp |
| `timeStr` | `string` | Time string |
| `nickName` | `string` | Nickname (downlink log document field) |
| `userName` | `string` | Username (downlink log document field) |


### Examples

#### Request example

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

getAnalyticsLogsPublishLog({
  devId: '6c272a8d82e3ed8300mizk',
  dpIds: '103,27',
  offset: 0,
  limit: 10,
})
  .then((response) => {
    console.log(response);
  })
  .catch();
```

#### Response example

```json
{
  "dpc": [],
  "dps": [
    {
      "dpId": 27,
      "nickName": "86-155****1913",
      "timeStamp": 1696842723,
      "timeStr": "2023-10-09 17:12:03",
      "userName": "86-155****1913",
      "value": "0000003e8006600000000"
    },
    {
      "dpId": 27,
      "nickName": "86-155****1913",
      "timeStamp": 1696842722,
      "timeStr": "2023-10-09 17:12:02",
      "userName": "86-155****1913",
      "value": "0000003e8006600000000"
    },
    {
      "dpId": 27,
      "nickName": "86-155****1913",
      "timeStamp": 1696842722,
      "timeStr": "2023-10-09 17:12:02",
      "userName": "86-155****1913",
      "value": "0000003e8006600000000"
    },
    {
      "dpId": 27,
      "nickName": "86-155****1913",
      "timeStamp": 1696842720,
      "timeStr": "2023-10-09 17:12:00",
      "userName": "86-155****1913",
      "value": "0000003e8006600000000"
    },
    {
      "dpId": 27,
      "nickName": "86-155****1913",
      "timeStamp": 1696842720,
      "timeStr": "2023-10-09 17:12:00",
      "userName": "86-155****1913",
      "value": "0000003e8006600000000"
    },
    {
      "dpId": 27,
      "nickName": "86-155****1913",
      "timeStamp": 1696842720,
      "timeStr": "2023-10-09 17:12:00",
      "userName": "86-155****1913",
      "value": "0000003e8006600000000"
    },
    {
      "dpId": 27,
      "nickName": "86-155****1913",
      "timeStamp": 1696842719,
      "timeStr": "2023-10-09 17:11:59",
      "userName": "86-155****1913",
      "value": "0000003e8006600000000"
    },
    {
      "dpId": 27,
      "nickName": "86-155****1913",
      "timeStamp": 1696842719,
      "timeStr": "2023-10-09 17:11:59",
      "userName": "86-155****1913",
      "value": "0000003e8006600000000"
    },
    {
      "dpId": 27,
      "nickName": "86-155****1913",
      "timeStamp": 1696842719,
      "timeStr": "2023-10-09 17:11:59",
      "userName": "86-155****1913",
      "value": "0000003e8006600000000"
    },
    {
      "dpId": 27,
      "nickName": "86-155****1913",
      "timeStamp": 1696842718,
      "timeStr": "2023-10-09 17:11:58",
      "userName": "86-155****1913",
      "value": "0000003e8006600000000"
    }
  ],
  "hasNext": true,
  "total": 97815
}
```


### Notes

1. This API is a cloud capability and must be authorized before use. For details, see the [cloud capability documentation](/en/miniapp/common/desc/tech-stack/api). **Cloud capabilities are not available in the `Developer Tools` environment; package the MiniApp or test on a real device.**
2. **To upgrade device log storage and unlock more features**, visit [Device log value-added service](https://www.tuya.com/vas/commodity/DEVICE_LOG_QUERY_V2). After upgrading, follow [the activation process after subscribing to device log storage](https://drive.weixin.qq.com/s?k=AGQAugfWAAkPDlmmAW). With upgraded storage, this API can retrieve more logs.
3. Commands sent through the Tuya MiniApp IDE virtual device plugin are **not** recorded in publish logs; only commands actually sent from a real client are recorded.
