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

# Token APIs

## Get authentication code

<mark style="color:blue;">`GET`</mark> `/login/open/tuya/login/v1/index.html?client_id=&redirect_uri=&state=`

Get authentication code accord to `client_id`,

#### Query Parameters

| Name          | Type   | Description                    |
| ------------- | ------ | ------------------------------ |
| client\_id    | string | client\_id is assigned by Tuya |
| redirect\_uri | string | the callback url               |
| state         | string |                                |

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

```
https://example.com/code?code=Ap4s8Os5d8sIPsjkd1012&state=a1b2
```

{% endtab %}
{% endtabs %}

#### Environment

This interface is provided by other systems with the following address:

**Test Environment**

```
China   https://pxy1-cn.wgine.com/ 
America https://pxy1-us.wgine.com/ 
Europe  https://pxy1-eu.wgine.com/
```

**Production Environment**

```
China  https://pxy1.tuyacn.com/ 
America https://pxy1.tuyaus.com/ 
Europe  https://pxy1.tuyaeu.com/
```

{% hint style="info" %}
Only this API depends on those environments !
{% endhint %}

## Get access token

<mark style="color:green;">`POST`</mark> `/v1.0/token`

#### Request Body

| Name        | Type    | Description                                                 |
| ----------- | ------- | ----------------------------------------------------------- |
| client\_id  | string  | <p>client\_id is assigned by Tuya<br></p>                   |
| grant\_type | integer | Authorization type, 1-simple mode 2-authorization code mode |
| code        | string  | Code is required when grand\_type is 2(authorization code)  |
| secret      | string  | secret is assigned by Tuya                                  |

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

```javascript
{
    "success": true, 
    "code": 0, 
    "msg": "", 
    "result": {
        "access_token": "", 
        "expire_time": 7200, 
        "refresh_token": ""
    } 
}
```

{% endtab %}
{% endtabs %}

## Refresh access token

<mark style="color:blue;">`GET`</mark> `/v1.0/token/{refresh_token}`

#### Path Parameters

| Name           | Type   | Description               |
| -------------- | ------ | ------------------------- |
| refresh\_token | string | It comes from /v1.0/token |

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

```javascript
{
    "success": true, 
    "code": 0, 
    "msg": "", 
    "result": {
        "access_token": "", 
        "expire_time": 7200, 
        "refresh_token": ""
    } 
}
```

{% endtab %}
{% endtabs %}
