User Management

Last Updated on : 2023-12-07 03:33:44download

This topic describes the APIs of synchronizing users, getting the user list, and getting user information.

API list

Request method API Description
POST /v1.0/apps/{schema}/user Synchronize users
GET /v2.0/apps/{schema}/users Get the user list
GET /v1.0/users/{uid}/infos Get user information

Synchronize users

API description

It is the account synchronization interface. You can create accounts and modify account information by different parameters according to your scenarios.

  • If you pass in the same username in the same application, the last user information will be updated.
  • If you directly use the interface in a Tuya OEM app, you can only log in with a mobile phone number and email address at present, and the hash rule for the password should be the MD5 algorithm.

API address

POST /v1.0/apps/{schema}/user

Request parameter

Parameter name Data type Parameter type Required Description
schema String URI Yes The unique identifier of an application, which corresponds to the identifier in the application management of the IoT Platform.
country_code String body Yes Country code.
username String body Yes Username.
Password String body Yes The user password. We recommend that you use the MD5 Hash password.
username_type Integer body Yes The type of username.
  • 1: mobile phone number
  • 2: email address
  • 3: others
Default value: 3
nick_name String body No Nickname.
time_zone_id String body No Time zone id.

Return parameter

Parameter name Data type Description
code Integer Error code.
success Boolean Determine whether the request succeeded or not.
true: succeeded
false: failed
msg String The message returned if the request fails. It will return null if the request succeeds.
result Object<result> The returned result.

Description of result

Parameter name Data type Description
uid String The Tuya user ID.

Request example

POST /v1.0/apps/testApp/user
{ "country_code":"86", "username":"182*****678", "password":"c7fb2740c5f******4ed765a479fa", "username_type":1, "time_zone_id": "Asia/Shanghai" }

Java SDK example

TuyaClient client = new TuyaClient(clientId, secret, RegionEnum.CN); String uid = client.registerUser("testApp","86","182*****678",MD5Util.getMD5("123456")"nickName",UserTypeEnum.MOBLIE); System.out.println("User synchronization succeeded: "+uid);

Return example

{ "success": true, "result": { "uid": "ay1534*****4744oIAa" } }

Error code

The following are common service exceptions for this interface. For more exception errors, see Error Code.

Error code Description
500 System error
1106 Illegal permission. Confirm whether the application schema is correct.
2403 The country code is not supported. Confirm whether it is in the current data center.
2021 Invalid mobile phone number. When the type of username is set to 1, the mobile phone number format is incorrect.
2022 Invalid email address. When the type of username is set to 2, the email address format is incorrect.

Get the user list

API description

  • This API is used to pull the user data related to the application that is built on the IoT Platform.
  • The fields that involves user privacy will be encrypted for security concern.
  • The API returns the data that is generated within the set time period, 30 days as the longest.

API address

GET /v2.0/apps/{schema}/users

Request parameter

Parameter name Data type Parameter type Required Description
schema String URI Yes App schme
page_no Int URL Yes The current page number
page_size Int URL Yes Page size. The value range is 0–100.
start_time Long URL Yes Start time, 10-digit timestamp.
end_time Long URL Yes End time, 10-digit timestamp.

Return parameter

Parameter name Data type Description
code Integer Error code.
success Boolean Determine whether the request succeeded or not.
true: succeeded
false: failed
msg String The message returned if the request fails. It will return null if the request succeeds.
result Object<result> User information

Description of result

Parameter name Data type Description
list Object See Description of list
has_more Boolean Determine whether there is more user data.
true: yes
false: no
total Integer The total number of users in the Schema.

Description of list

Parameter name Data type Description
uid String User ID
username String Username
mobile String The mobile phone number which returns for users registered by a mobile phone number.
email String The email address which returns for users registered by a email address.

Request example

GET /v2.0/apps/testapp/users?page_no=1&page_size=10&start_time=1602848780&end_time=1603809946

Java SDK example

TuyaClient client = new TuyaClient(clientId, secret, RegionEnum.CN); UserList result = client.getUsers("testApp",1,10); System.out.println("Get the user list: "); System.out.println(JSONObject.toJSONString(result));

Return example

{ "success":true, "t":1551851043862, "result":{ "list":[ { "country_code":"86", "uid":"ay15264******aK4Jo", "username":"****", "mobile":"****" }, { "country_code":"86", "uid":"ay1526******09hBOKe", "username":"****", "email":"****" } ], "has_more":false, "total":12 } }

Error code

The following are common service exceptions for this interface. For more exception errors, see Error Code.

Error code Description
500 System error
1003 Invalid grant type
1107 Invalid code

Get user information

API description

This interface is used to get user information.

API address

GET /v1.0/users/{uid}/infos

Request parameter

Parameter name Data type Parameter type Required Description
uid String URI Yes User ID

Return parameter

Parameter name Data type Description
code Integer Error code.
success Boolean Determine whether the request succeeded or not.
true: succeeded
false: failed
msg String The message returned if the request fails. It will return null if the request succeeds.
result Object<result> User information

Description of result

Parameter name Data type Description
country_code String Country code
avatar String Avatar
mobile String Phone
nick_name String Nickname
uid String User ID
username String Username
create_time Long Creation time
update_time Long Update time

Request example

GET /v1.0/users/ay876543456789/infos

Return example

{ "result": { "avatar": "", "create_time": 1582601946, "mobile": "86-153******93", "nick_name": "", "uid": "ay1587******2vqTA", "update_time": 1582601946, "username": "86-153******93" }, "success": true, "t": 1586153261345 }

Error code

The following are common service exceptions for this interface. For more exception errors, see Error Code.

Error code Description
500 System error