Publishes a message to multiple devices of a product by using a custom topic.

Usage notes

  • This operation can be used only by users in the whitelist. If you need to use this operation, submit a ticket.
  • You can call this operation to publish a message to a maximum of 100 devices of a product at a time.
  • The BatchPub operation cannot be used to send commands of setting properties or calling services. If you need to set properties, use the SetDeviceProperty or SetDevicesProperty operation. If you need to call services, use the InvokeThingService or InvokeThingsService operation.
  • Each Alibaba Cloud account can run a maximum of 50 queries per second (QPS).
    Note 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 BatchPub

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

DeviceName.N RepeatList Yes newdevice1

The name of the device that receives the message.

Note
  • This parameter is used together with the ProductKey parameter. The specified devices must belong to the same product.
  • You can specify up to 100 device names in a single call.
MessageContent String Yes aGVsbG8gd29ybGQ%3D

The body of the message to be published. The maximum size of a message is 256 KB.

To generate a message body, you must convert the raw message into binary data and perform Base64 encoding.

ProductKey String Yes a1BwAGV****

The key of the product to which the devices that receive the message belong.

TopicShortName String Yes get

The suffix in the name of the custom topic.

The name of a custom topic is in the following format: /${productKey}/${deviceName}/user/${TopicShortName}, where ${TopicShortName} specifies the suffix.

Note You must specify the Subscribe permission, or Publish and Subscribe permissions for the topic. Make sure that all devices subscribe to the topic.

You can use the following methods to view custom topics:

  • On the Topic Categories tab of the details page for a product, view the custom topics of the product.
  • On the Topic List tab of the details page for a device, view the custom topics that the device is subscribed to.
  • Call the QueryProductTopic operation to query the custom topics of a product.
IotInstanceId String No iot-cn-0pp1n8t****

The ID of the instance. This parameter is not required for the public instance but required for Enterprise Edition instances.

Qos Integer No 0

The quality of service (QoS) level of the message. Valid values:

  • 0: The message is published at most once.
  • 1: The message is published at least once.

Default value: 0.

Note IoT Platform stores QoS 1 messages for up to seven days. IoT Platform does not store QoS 0 messages.

In addition to the preceding operation-specific request parameters, you must specify common request parameters when you call this operation. For more information about common request parameters, see Common 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.

ErrorMessage String A system exception 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 was successful.

  • true: The call was successful.
  • false: The call failed.

Examples

Sample requests

http(s)://iot.cn-shanghai.aliyuncs.com/? Action=BatchPub
&DeviceName.1=newdevice1
&MessageContent=aGVsbG8gd29ybGQ%3D
&ProductKey=a1BwAGV****
&TopicShortName=get
&<Common request parameters>

Sample success responses

XML format

<BatchPubResponse>
  <RequestId>9E76053E-26ED-4AB4-AE58-8AFC3F1E7E8E</RequestId>
  <Success>true</Success>
</BatchPubResponse>

JSON format

{
  "RequestId": "9E76053E-26ED-4AB4-AE58-8AFC3F1E7E8E",
  "Success": true
}

Error codes

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