Sets the desired values of multiple device properties.

Limits

  • The desired values of read-only properties cannot be queried.
  • A maximum of 10 desired property values can be set in a single call.
  • After a device is created, the value of the Version parameter is 0. If you specify the Version parameter when you set a desired property value for the first time, set the value of the Version parameter to 0.
  • Each Alibaba Cloud account can run a maximum of 50 queries per second (QPS).
    Note Resource Access Management (RAM) users of an Alibaba Cloud account share the quota of the account.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes SetDeviceDesiredProperty

The operation that you want to perform. Set the value to SetDeviceDesiredProperty.

Items String Yes {"Temperature":35}

The property that you want to set. This parameter is a JSON string. Format: Key:Value. Example: {"Temperature":35}. You can set a maximum of 10 desired property values.

  • Key specifies the identifier of the property. You can view the property identifier in the IoT Platform console. Go to the Define Feature tab of the Product Details page. You can also call the QueryThingModel operation and view the property identifier in the returned TSL data.

    If the temperature property belongs to a custom module named testFb, this parameter is set to {"testFb:temperature":35}.
    Note The specified property must allow read/write access. If you specify a read-only property, the setting fails. The property identifier must be unique.
  • Value specifies the desired value of the property. The value must match the data type and value range that are defined for the property.
    Note If you set Value to null, the desired value of the property is cleared.
Versions String Yes {"Temperature":2}

The version number of the desired property value. This parameter is a JSON string. Format: Key:Value. Example: {"Temperature":2}.

  • Key specifies the identifier of the property. You can view the property identifier in the IoT Platform console. Go to the Define Feature tab of the Product Details page.
    Note The property identifier must be unique.
  • Value specifies the version number of the desired property value.

    Set Value to 0 when you set a desired property value for the first time. After you set the property value, the version number changes to 1. Each time you set a desired property value, IoT Platform automatically increases the version number by 1. After you set a desired property value the second time, the version number changes to 2. When you set a desired property value the third time, set the version number to 2. After you set the desired property value, the version number changes to 3.
    Note If the version number that you specify for this parameter is not the current version number, the server rejects the request. If you are not sure about the current version number, you do not need to specify a version number. In this case, you must enter a valid JSON object {}.
IotInstanceId String No iot_instc_pu****_c*-v64********

The instance ID. This parameter is not required for public instances. However, this parameter is required for Enterprise Edition instances.

IotId String No Q7uOhVRdZRRlDnTLv****00100

The ID of the device. The ID is the unique identifier that is by IoT Platform to the device.

Note If you specify this parameter, you do not need to specify the ProductKey or DeviceName parameter. The IotId parameter specifies a unique identifier for the device, and corresponds to a combination of the ProductKey and DeviceName parameters. If you specify the IotId parameter and a combination of the ProductKey and DeviceName parameters at the same time, only the IotId parameter is used.
DeviceName String No light

The name of the device.

Note If you specify this parameter, you must also specify the ProductKey parameter.
ProductKey String No a1BwAGV****

The ProductKey of the product to which the device belongs.

Note If you specify this parameter, you must also specify the DeviceName parameter.

In addition to the preceding operation-specific request parameters, you must specify common request parameters when you call this API operation. For more information, see Common request parameters.

Response parameters

Parameter Type Example Description
Code String iot.system.SystemException

The error code returned if the call fails. For more information, see Error codes.

Data Struct

The data returned if the call succeeds. For more information, see the following parameters.

MessageId String 300511751

The ID of the message that IoT Platform sends to the device. The message is sent to set desired property values.

Versions String {\"Temperature\":2}

The current version numbers of the desired property values.

ErrorMessage String A system exception has occurred.

The error message returned if the call fails.

RequestId String E55E50B7-40EE-4B6B-8BBE-D3ED55CCF565

The ID of the request.

Success Boolean true

Indicates whether the call succeeds.

  • true: The call succeeded.
  • false: The call failed.

Examples

Sample requests

https://iot.cn-shanghai.aliyuncs.com/?Action=SetDeviceDesiredProperty
&ProductKey=a1BwAGV****
&DeviceName=device1
&Items=%7B%22LightAdjustLevel%22%3A1%7D
&Versions=%7B%22LightAdjustLevel%22%3A10%7D
&<Common request parameters>

Sample success responses

XML format

<SetDeviceDesiredPropertyResponse>
  <Data>
        <MessageId>300511751</MessageId>
        <Versions>{"LightAdjustLevel":2}</Versions>
  </Data>
  <RequestId>AADE79D2-B328-4FC6-A3E0-34BB23BCA440</RequestId>
  <Success>true</Success>
</SetDeviceDesiredPropertyResponse>

JSON format

{
    "Data": {
        "MessageId": "300511751",
        "Versions": "{\"LightAdjustLeve\":2}"
    },
    "RequestId": "AADE79D2-B328-4FC6-A3E0-34BB23BCA440",
    "Success": true
}

Error codes

For a list of error codes, visit the API Error Center.