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

Usage notes

  • 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.


Alibaba Cloud provides OpenAPI Explorer to simplify API usage. 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.

  • 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. The device names must be unique.
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 ProductKey of the product to which the device belongs.

TopicShortName String Yes get

The suffix of the custom topic.

A custom topic is in the following format: /${productKey}/${deviceName}/user/${TopicShortName}. ${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 Product Details page, view the custom topics of the product.
  • On the Topic List tab of the Device Details page, view the custom topics to which the device has subscribed.
  • Call the QueryProductTopic operation to query the custom topics of the product.
IotInstanceId String No iot-cn-0pp1n8t****

The ID of the instance. You can view the instance ID on the Overview page in the IoT Platform console.

  • If your instance has an ID, you must configure this parameter. If you do not set this parameter, the call fails.
  • If your instance has no Overview page or ID, you do not need to set this parameter.

For more information, see Overview.

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 7 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, 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.

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.


Sample requests:

&<Common request parameters>

Sample success responses

XML format


JSON format

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

Error codes

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