English
English
简体中文
Contact Us
Register
Log In
Language
English
English
简体中文
Contact Us
Log In
Register
Go to main website
App Develop

App Development Platform

App development platform provides multiple development methods such as no-code or IoT App SDK development to maximize the monetization of IoT apps.
layoutIndex
DocumentationCloud DevelopmentBest PracticeSet Postman Environment and Call API Operations

Set Postman Environment and Call API Operations

Last Updated on : 2021-09-15 06:55:08download

The Cloud Development Platform provides API Explorer for you to debug the APIs quickly. Also, you can use Postman to make API requests. For example, Postman can be used to get device information or control devices. This topic describes how to set the Postman environment variables that are used in the API operations of the Cloud Development Platform. It also describes the procedure to call these API operations.

Configure environment

  1. Install Postman v8.2.2 or later.

    Note: Too low version will cause incompatibility of tuya API Package, so please upgrade to the recommended version or above

  2. Click Workspace in the top-left corner of the page to select a workspace, and choose Import > Upload Files to import the API Package and API Environment Package.

    Note: If an earlier version of signature verification is used, you can download Tuya OpenAPI Package—Earlier Version.

    Set Postman Environment and Call API Operations

  3. Set Postman environment variables.

    In the left-side navigation pane, click Environments and double-click API environment package to set the parameters. Save the settings, click Set active, and then confirm that the No Environment in the top-right corner of the page is changed to API environment package.

    Parameter
    Description
    url The endpoint of the Tuya IoT Cloud service that you want to manage.
    Note: For example, the endpoint of the Tuya IoT Cloud service that is deployed in mainland China is set to https://openapi.tuyacn.com. For more information, see Endpoints.
    client_id The username that is authorized to access the specified cloud development project. The value is the same as the value of the accessId parameter on the Cloud Development Platform.
    secret The password for the username. The value is the same as the value of the accessKey parameter on the Cloud Development Platform.
    device_id (optional) The device ID. You can view the information about the device in the app.
    Note: Click the device that is added to the app and click the pencil icon in the top right corner of the page to view the device ID in the Device Information section.
    schema (optional) The channel identifier of the app. Set the value based on the app package name.
    For example, if your app package name is com.aa.bb, the value of schema is aabb.

    Set Postman Environment and Call API Operations

    Note: Fill the values on CURRENT VALUE column.

Call API operations

Prerequisites

Procedure

  1. Get a token.
    Call the Get access_token with simple mode operation to get the value of access_token. The value is required when you call API operations to control devices.
    Set Postman Environment and Call API Operations

  2. Call the Get device data points operation to get the data points supported by the device. You can use them to control the device.
    Set Postman Environment and Call API Operations

  3. Call the Send device commands operation to control the device.
    You can send a command that is supported by the device to achieve the required effect.

    Set Postman Environment and Call API Operations

    The following code block in the API request body shows how to start a robot vacuum:

    {
    	"commands":[
    		{
    			"code": "power",
    			"value":true
    		}
    	]
    }
    

Operation result

The robot vacuum is started to run as expected.

Set Postman Environment and Call API Operations