Request Structure

Last Updated on : 2023-07-05 02:16:42download

This topic describes the request methods, endpoints, and request header parameters that are used in your API requests to cloud development.

Request methods

The API requests to cloud development support the following request methods.

Method Description
GET Requests the server to return the specified resources.
PUT Requests the server to update the specified resources.
POST Requests the server to perform the specified operations.
DELETE Requests the server to delete the specified resources.

When the request method POST is used, the Content-Type parameter must be set to application/json.

Endpoints

Cloud development API endpoints can vary depending on different countries or regions. You can select an endpoint for the country or region where your devices are deployed. This makes your services more responsive to API requests.

Region Endpoint
China Data Center https://openapi.tuyacn.com
Western America Data Center https://openapi.tuyaus.com
Eastern America Data Center https://openapi-ueaz.tuyaus.com
Central Europe Data Center https://openapi.tuyaeu.com
Western Europe Data Center https://openapi-weaz.tuyaeu.com
India Data Center https://openapi.tuyain.com

Request header parameters

The following table lists the common request header parameters used in the API requests to cloud development. You must set the values of the required parameters in the request headers.

Parameter Type Location Required Description
client_id
String
header Yes The user ID.
sign String header Yes The signature that is generated by the specified signature algorithm.
sign_method String header Yes The signature digest algorithm. Set the value to HMAC-SHA256.
t Long header Yes The 13-digit standard timestamp.
lang String header No The type of language. Set the value to zh for a service that is deployed in mainland China and set the value to en for a service that is deployed outside mainland China.
access_token String header Yes The information about the specified token.
Note: This parameter is not required when you make API requests to get or refresh tokens.
nonce String header No The universally unique identifier (UUID) automatically generated when an API request is made.
Note: This parameter is not required when you use a legacy signature solution.
Signature-Headers String header No The header field of the signature customized by you.
Note: This parameter is not required when you use a legacy signature solution.

Sample request

Take the API request to get the user list as an example. With 50 entries returned on each page, get the list of user entries that were generated from 00:00:00, May 1, 2021 to 00:00:00, May 15, 2021. The request to get the first page of user entries is as follows:

  • API request

    GET:https://openapi.tuyacn.com/v2.0/apps/schema/users?page_no=1&page_size=50&start_time=1619798400&end_time=1621008000
    
  • Request header

    client_id: 1KAD46OrT9HafiKd****
    sign: C5EFD19AD45E33A060C0BE47AEF65D975D54B2D70CBAA7A1ACA1A7D0E5C0****
    sign_method: HMAC-SHA256
    t: 1588925778000
    access_token: 3f4eda2bdec17232f67c0b188af3****
    nonce: 5138cc3a9033d69856923fd07b49****
    Signature-Headers: area_id:request_id
    area_id: 29a33e8796834b1**** // User-defined
    request_id: 8afdb70ab2ed11eb85290242ac13**** // User-defined