Broadcast push sends the same message to all devices on the network. These messages are created from a template.
Scheduled and recurring pushes are not supported when the target audience is a mobile analytics group or a custom tag group.
Before you call this API, complete the following:
Create a target template in the Message Push console. Ensure that the template includes placeholders to enable personalized messages for different push IDs. For more information, see Create a template.
Import the SDK dependencies. For more information, see SDK preparation.
Request parameters
Parameter name | Type | Required | Example | Description |
classification | String | No | 1 | The message type for the vivo push channel.
The default value is 1. |
taskName | String | Yes | Broadcast test task | The name of the push task. |
appId | String | Yes | ONEX570DA89211721 | The mPaaS App ID. |
workspaceId | String | Yes | test | The mPaaS workspace. |
deliveryType | Long | Yes | 1 | The target ID type. Valid values:
|
msgkey | String | Yes | 1578807462788 | The business message ID. This ID is user-defined and must be unique. |
expiredSeconds | Long | Yes | 300 | The message validity period in seconds. |
templateName | String | Yes | Broadcast template | The template name. Create the template in the console. |
templateKeyValue | String | No | {"content":"Announcement content"} | The template parameters in a map format. These parameters correspond to the template specified by |
pushStatus | Long | No | 0 | The logon status for broadcast push.
|
bindPeriod | Integer | No | The logon duration. This parameter is required when
Note The | |
unBindPeriod | Long | No | The logoff duration. This parameter is required when
| |
androidChannel | Integer | No | The Android message channel.
| |
strategyType | int | No | 1 | The push policy type.
The default value is 0. |
StrategyContent | String | No | {\”fixedTime\”:1630303126000,\”startTime\”:1625673600000,\”endTime\”:1630303126000,\”circleType\”:1,\”circleValue\”:[1, 7],\”time\”:\”13:45:11\”} | The details of the push policy as a JSON string. This parameter is required when |
thirdChannelCategory | Map | No | thirdChannelCategory: { "hms": "9", //Huawei FINANCE message "vivo": "1" //vivo IM message } | Used to pass the vendor message categorization. For more information, see Vendor message categorization. |
notifyLevel | Map | No | notifyLevel: {"oppo":"2"//OPPO notification bar + lock screen} | The vendor message notification level. For example, the OPPO message levels are as follows:
|
miChannelId | String | No | "123321" | The channelId of the Xiaomi vendor push channel. |
timeMode | Integer | No | 0 | The time mode.
|
bindStartTime | Long | No | 1746720000000 | The start timestamp for attachment. |
bindEndTime | Long | No | 1746806219999 | The end timestamp for attachment. |
unBindStartTime | Long | No | 1746720000000 | The start timestamp for detachment. |
unBindEndTime | Long | No | 1746806219999 | The end timestamp for detachment. |
StrategyContent field description
Pass the value as a JSON string.
Parameter name | Type | Required | Example | Description |
fixedTime | long | No | 1630303126000 | The timestamp for a scheduled push. The value is in milliseconds and must be accurate to the second. The |
startTime | long | No | 1640966400000 | The start timestamp for the loop epoch. The value is a UNIX timestamp in milliseconds and must be accurate to the day. This parameter is required when the push policy type is loop ( |
endTime | long | No | 1672416000000 | The end timestamp of the recurring cycle, in milliseconds. The value must be accurate to the day, and the end time cannot be later than 180 days after the current day. |
circleType | int | No | 3 | Loop type:
When the push policy type is loop (the value of |
circleValue | int[] | No | [1,3] | The recurrence value.
If the push policy type is loop (the value of |
time | String | No | 09:45:11 | The time for the loop push, in |
The maximum number of pending scheduled or recurring push tasks is 100 by default.
The recurring epoch starts at 00:00 on the start date and ends at 24:00 on the end date.
The start and end times for a recurring task cannot be earlier than 00:00 on the current day. The end time cannot be earlier than the start time.
Response parameters
Parameter name | Type | Example | Description |
RequestId | String | B589F4F4-CD68-3CE5-BDA0-6597F33E23916512 | The request ID. |
ResultCode | String | OK | The result code of the request. |
ResultMessage | String | param is invalid | The description of the request error. |
PushResult | JSON | The result of the request. | |
Success | boolean | true | The request status. The |
ResultMsg | String | param is invalid | The content of the request error. The |
Data | String | 903bf653c1b5442b9ba07684767bf9c2 | The ID of the scheduled push task. This field is not empty when |
Code examples
Make sure your AccessKey has the `AliyunMPAASFullAccess` permission. For more information, see Application-level access control for RAM accounts.
Java code example
Click here to learn how to obtain the AccessKey ID and AccessKey secret used in the code example below.
import com.alibaba.fastjson.JSON;
import com.aliyun.mpaas20201028.Client;
import com.aliyun.mpaas20201028.models.PushBroadcastRequest;
import com.aliyun.mpaas20201028.models.PushBroadcastResponse;
import com.aliyun.teaopenapi.models.Config;
import java.text.SimpleDateFormat;
public static void main(String[] args) throws Exception {
// An Alibaba Cloud account AccessKey has full access to all APIs. We recommend that you use a RAM user for API calls and daily O&M.
// We strongly recommend that you do not hard-code the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and threaten the security of all your resources.
// This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// We recommend that you configure the environment variables first.
Config config = new Config();
// Required. Your AccessKey ID.
config.setAccessKeyId(System.getenv("MPAAS_AK_ENV"));
// Required. Your AccessKey secret.
config.setAccessKeySecret(System.getenv("MPAAS_SK_ENV"));
// The REGION_ID and Endpoint of mPaaS. The Hangzhou non-Gold environment is used as an example.
config.setRegionId("cn-hangzhou");
config.setEndpoint("mpaas.cn-hangzhou.aliyuncs.com");
Client client = new Client(config);
PushBroadcastRequest request = new PushBroadcastRequest();
request.setAppId("ONEX570DA89211721");
request.setWorkspaceId("test");
request.setTenantId("xxx");
request.setTemplateName("Test Template");
request.setExpiredSeconds(180L);
request.setTaskName("Broadcast Task");
request.setAndroidChannel(2);
// 1: Android, 2: iOS, 7: HarmonyOS
request.setDeliveryType(1L);
// 0: Fixed number of days, 1: Time range
// request.setTimeMode(1);
// 0: Query attached devices, 1: Query attached/detached device information, 2: Query detached device information
request.setPushStatus(0L);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long startTime = dateFormat.parse("2024-05-20 15:59:48").getTime();
long endTime = dateFormat.parse("2024-05-20 15:59:48").getTime();
request.setBindStartTime(startTime);
request.setBindEndTime(endTime);
request.setMsgkey(String.valueOf(System.currentTimeMillis()));
System.out.println("request==>"+JSON.toJSONString(request));
PushBroadcastResponse acsResponse = client.pushBroadcast(request);
System.out.println("response==>"+JSON.toJSONString(acsResponse));
}Python code example
# -*- coding: utf8 -*-
from aliyunsdkcore.client import AcsClient
from aliyunsdkmpaas.request.v20190821 import PushBroadcastRequest
import json
import time
// An Alibaba Cloud account AccessKey has full access to all APIs, which poses a high security risk. We strongly recommend that you create and use a RAM user for API calls and daily O&M. Log on to the RAM console to create a RAM user.
// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// We strongly recommend that you do not hard-code the AccessKey and AccessKey secret in your code to avoid key leakage.
// We recommend that you configure the environment variables first.
# Initialize AcsClient instance
String accessKeyId = System.getenv("MPAAS_AK_ENV");
String accessKeySecret = System.getenv("MPAAS_SK_ENV");
client = AcsClient(
accessKeyId,
accessKeySecret,
"cn-hangzhou"
);
# Initialize a request and set parameters
request = PushBroadcastRequest.PushBroadcastRequest()
request.set_endpoint("mpaas.cn-hangzhou.aliyuncs.com")
request.set_AppId("ONEX570DA89211720")
request.set_WorkspaceId("test")
request.set_TemplateName("broadcastTemplate")
templatekv = {"content":"This is an announcement"}
request.set_TemplateKeyValue(json.dumps(templatekv))
request.set_DeliveryType(1)
request.set_TaskName("Python test broadcast task")
request.set_ExpiredSeconds(600)
request.set_Msgkey(str(time.time()))
# Print response
response = client.do_action_with_exception(request)
print responseNode.js code example
const sdk = require('@alicloud/mpaas20190821');
const { default: Client, PushBroadcastRequest } = sdk;
// Create a client
// An Alibaba Cloud account AccessKey has full access to all APIs, which poses a high security risk. We strongly recommend that you create and use a RAM user for API calls and daily O&M. Log on to the RAM console to create a RAM user.
// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// We strongly recommend that you do not hard-code the AccessKey and AccessKey secret in your code to avoid key leakage.
// We recommend that you configure the environment variables first.
String accessKeyId = System.getenv("MPAAS_AK_ENV");
String accessKeySecret = System.getenv("MPAAS_SK_ENV");
const client = new Client({
accessKeyId,
accessKeySecret,
endpoint: 'mpaas.cn-hangzhou.aliyuncs.com',
apiVersion: '2019-08-21'
});
// Initialize request
const request = new PushBroadcastRequest();
request.appId = "ONEX570DA89211720";
request.workspaceId = "test";
request.templateName= "broadcastTemplate";
const templatekv = {
content: 'This is an announcement',
};
request.templateKeyValue = JSON.stringify(templatekv);
request.deliveryType = 1;
request.taskName = "Node.js test task";
request.expiredSeconds=600;
const extendedParam = {
test: 'Custom extended parameter'
};
request.extendedParams = JSON.stringify(extendedParam);
request.msgkey = String(new Date().valueOf())
// Call API
try {
client.pushBroadcast(request).then(res => {
console.log('SUCCESS', res);
}).catch(e => {
console.log('FAIL', e);
});
} catch(e) {
console.log('ERROR', e);
}PHP code example
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\MPaaS\MPaaS;
AlibabaCloud::accessKeyClient('accessKeyId', 'accessKeySecret')
->regionId('cn-hangzhou')
->asDefaultClient();
class Demo {
public function run() {
try {
$this->broadcastPush();
} catch (\Exception $e) {
}
}
public function broadcastPush(){
$request = MPaaS::v20190821()->pushBroadcast();
$result = $request->host("mpaas.cn-hangzhou.aliyuncs.com")
// Specifies whether to enable the debug mode
->debug(true)
->withAppId("ONEX570DA89211720")
->withWorkspaceId("test")
->withTemplateName("broadcastTemplate")
->withTemplateKeyValue(
json_encode(["content" => "This is an announcement"])
)
->withDeliveryType(1)
->withTaskName("PHP test broadcast task")
->withExpiredSeconds(600)
->withMsgkey("". time())
->request();
}
}