> For the complete documentation index, see [llms.txt](https://tuya.gitbook.io/open-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tuya.gitbook.io/open-api/device-apis.md).

# Device APIs

The chapter will introduce to you how to interact with the devices.

## Get devices

<mark style="color:blue;">`GET`</mark> `/v1.0/users/{uid}/devices?access_token=&sign=&t=`

This api allows you to get devices of a user that is related to Tuya cloud.

#### Path Parameters

| Name | Type   | Description     |
| ---- | ------ | --------------- |
| uid  | string | User id in Tuya |

#### Query Parameters

| Name          | Type   | Description                                       |
| ------------- | ------ | ------------------------------------------------- |
| access\_token | string | Access token                                      |
| sign          | string | Refer to <https://tuya.gitbook.io/open-api/#sign> |
| t             | string | timestamp, 13-bit                                 |

{% tabs %}
{% tab title="200 Cake successfully retrieved." %}

```javascript
{
      "success": true,
      "code": 0,
      "msg": "",
      "result": [
          {
              "device_id": "6c362ac3c53fbd6f3ewqfa",
              "name": "机顶盒3",
              "status": [
                  {
                      "code": "switch_power",
                      "value": "false",
                      "mode": "rw"
                  },
                  {
                      "code": "confirm",
                      "value": "false",
                      "mode": "rw"
                  }
              ]
          },
          {
              "device_id": "6c6ca9545208069126vx1s",
              "name": "电视3",
              "status": [
                  {
                      "code": "switch_power",
                      "value": "false"
                  },
                  {
                      "code": "confirm",
                      "value": "false",
                      "mode": "rw"
                  }
              ]
          }
      ]
  }
```

{% endtab %}
{% endtabs %}

#### About mode

```
rw: read&write
ro: read only
wr: write only
```

## Get device detail

<mark style="color:blue;">`GET`</mark> `/v1.0/devices/{device_id}?access_token=&sign=&t=`

#### Path Parameters

| Name       | Type   | Description |
| ---------- | ------ | ----------- |
| device\_id | string | Device id   |

#### Query Parameters

| Name          | Type   | Description |
| ------------- | ------ | ----------- |
| access\_token | string |             |
| sign          | string |             |
| t             | string |             |

{% tabs %}
{% tab title="200 " %}

```javascript
{
      "success": true,
      "code": 0,
      "msg": "",
      "result": {
            "id": "6c6ca9545208069126vx1s", //device id
            "uid": "", //user id
            "local_key": "" //device local secret
            "product_id": "", //product id
            "sub": false, // is sub device
            "uuid": "" //unique id of device, like mac address in PC
            "owner_id": 20086 //device owner     
      }
  }
```

{% endtab %}
{% endtabs %}

## Get device status

<mark style="color:blue;">`GET`</mark> `/v1.0/devices/{device_id}/status?access_token=&sign=&t=`

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
|      | string | device id   |

#### Query Parameters

| Name          | Type   | Description |
| ------------- | ------ | ----------- |
| access\_token | string |             |
| sign          | string |             |
| t             | string |             |

{% tabs %}
{% tab title="200 " %}

```javascript
{
       "success": true,
       "code": 0,
       "msg": "",
       "result": [
           {
               "code": "led_switch",
               "value": "false",
               "mode": "rw"
           },
           {
               "code": "work_mode",
               "value": "scene",
                "mode": "rw"
           }
       ]
   }
```

{% endtab %}
{% endtabs %}

## Execute device command

<mark style="color:green;">`POST`</mark> `/v1.0/devices/{device_id}/commands?access_token=&sign=&t=`

#### Path Parameters

| Name       | Type   | Description |
| ---------- | ------ | ----------- |
| device\_id | string | device id   |

#### Query Parameters

| Name          | Type   | Description |
| ------------- | ------ | ----------- |
| access\_token | string |             |
| sign          | string |             |
| t             | string |             |

#### Request Body

| Name       | Type   | Description |
| ---------- | ------ | ----------- |
| commands   | array  |             |
| device\_id | string |             |

{% tabs %}
{% tab title="200 " %}

```javascript
{
    "success": true,
    "code": 0,
    "msg": ""
}
```

{% endtab %}
{% endtabs %}

#### commands

```javascript
[
    {
        "code": "switch_led",
        "value": true
    },
    {
        "code": "bright",
        "value": 30
    }
]
```

## Get device functions

<mark style="color:blue;">`GET`</mark> `/v1.0/devices/{device_id}/functions?access_token=&sign=&t=`

#### Path Parameters

| Name       | Type   | Description |
| ---------- | ------ | ----------- |
| device\_id | string |             |

#### Query Parameters

| Name          | Type   | Description |
| ------------- | ------ | ----------- |
| access\_token | string |             |
| sign          | string |             |
| t             | string |             |

{% tabs %}
{% tab title="200 " %}

```javascript
{
    "success": true,
    "code": 0,
    "msg": "",
    "result": {
        "category":"dj",
        "desc":"light",
        "functions": [
            {
                "code": "switch",
                "type": "boolean",
                "values":[true, false],
                "desc":"true:turn on, false:turn off"
            },{
                "code": "work_mode",
                "type": "string",
                "values":["white", "colour", "scene"]
            },{
                "code": "bright",
                "type": "int",
                "values":[],           
                "desc": "0-10000"
            },{
                "code": "color_temperature",
                "type": "int",
                "values":[],
                "desc": "0-10000"
            },{
                "code": "countdown",
                "type": "int",
                "values":[],
                "desc": "0-86400, unit:seconds"
            },{
                "code": "music",
                "type": "int",
                "values":[],
                "desc": "RGB 0-255"
            }
        ]
    }
}
```

{% endtab %}
{% endtabs %}
