Set Postman Environment and Call API Operations

Last Updated on : 2024-09-10 08:42:27

The application development services allow you to 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 up the Postman environment variables and call these API operations.

Set up the environment

  1. Install the Postman desktop agent v8.2.2 or later.

    An earlier version might be incompatible with Tuya’s API package. Upgrade to the recommended version or later.

  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.

    Set Postman Environment and Call API Operations
  3. Set Postman environment variables.

    In the left-side navigation pane, click Environments and double-click Tuya Cloud 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 Tuya Cloud API environment package.

    Parameter
    Description
    url The endpoint of the Tuya service that you want to manage.
    Note: If you have any questions, contact Tuya’s project manager.
    client_id The username that is authorized to access the specified cloud project. The value is the same as the value of the Access ID parameter on the Tuya IoT Development Platform.
    secret The password for the username. The value is the same as the value of the Access Key parameter on the Tuya IoT Development Platform.
    device_id (optional) The device ID. You can view the device information on the app.
    Note: Click the device that is added to the app and click the edit icon in the top right corner of the page to view the device ID in the Device Information section.
    schema (optional) The schema of the app. Set the value based on the app package name.
    Note: For example, if your app package name is com.aa.bb, the value of schema is aabb.
    Set Postman Environment and Call API Operations

    Fill the values of environmental parameters in the CURRENT VALUE column.

Call API operations

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