> 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/master.md).

# Tuya Open Platform Access Guide

## Introduction

### Environment

* Test Environment

```
China    https://openapi-cn.wgine.com
American https://openapi-us.wgine.com
Europe   https://openapi-eu.wgine.com
```

* Production Environment

```
China    https://openapi.tuyacn.com
American https://openapi.tuyaus.com
Europe   https://openapi.tuyaeu.com
```

### �Request Method

The list below are the request methods supported by Tuya

* GET
* PUT
* POST
* DELETE

> NOTE: The `content_type` should be `application/json` when the request method is `PUT` or `POST`

### Response Result

In most case, we will return data in json format, such as:

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

�or

```javascript
{
    "code": 100323,
    "msg": "token非法",
    "success": false
}
```

### �Sign

Every request should bring `sign` param to the server except the API of getting authentication code and token.The signature generation rules is as follow:

```
sign = MD5(client_id + access_token + secret + t).toUpperCase()
```

If the `sign` is less than 32 characters, it will be padded with 0 before it, then convert it to uppercase.

> It should be noted that for a request URL, the validity period is 5 minutes.

#### Parameter Description

| Parameter Name | Type   | Description                          | Required |
| -------------- | ------ | ------------------------------------ | -------- |
| client\_id     | string | `client_id` will be assigned by Tuya | Y        |
| access\_token� | string | can be get from`/v1.0/token`         | Y        |
| secret         | string | `secret` will be assigned by Tuya    | Y        |
| t              | long   | 13-bit standard timestamp            | Y        |

### Public parameters

In addition to the API to get the authorization code (code) and token, other API should add the following parameters to the URL:

| Parameter Name | Type   | Description                                                           | Required |
| -------------- | ------ | --------------------------------------------------------------------- | -------- |
| sign           | string | The signature calculated by the signature algorithm introduced above. | Y        |
| access\_token  | string | Access token,  can be get from /v1.0/token                            | Y        |
| t              | long   | 13-bit standard timestamp                                             | Y        |

### Authorization Mode

**Simple Mode**

The caller calls `/v1.0/token/` API to the server to get a token according to the client\_id and secret provided by Tuya.

#### Authorization code mode

The authorization code mode requires the Tuya user's authorization, and then the caller gets an authorization code (code), and then calls the `/v1.0/token` API according to the authorization code to exchange the token with the server.
