All Products
Search
Document Center

Mobile Platform as a Service:Template push

Last Updated:Oct 15, 2025

Template push is the process of sending messages to a single target ID using a predefined template. The same template can be applied to multiple IDs.

Before using this API, ensure that you have completed the following:

  • Create the desired template in the message push console. For more information, see Create a template.

  • Add SDK dependencies. For more information, see SDK preparation.

Request parameters

Parameter name

Type

Required

Example

Description

classification

String

No

1

Used to pass the message type of the vivo push channel:

  • 0 - Operational message

  • 1 - System message

If not filled, the default is 1.

taskName

String

Yes

Template test

Push task name.

appId

String

Yes

ONEX570DA89211721

mPaaS App ID

workspaceId

String

Yes

test

mPaaS workspace

deliveryType

Long

Yes

3

Target ID type, with the following options:

  • 1 - Android device dimension

  • 2 - iOS device dimension

  • 3 - User dimension

  • 5 - Real-time activity pushToken

  • 6 - Real-time activity activityId

targetMsgkey

String

Yes

{“user1024”:”1578807462788”}

Push target, in Map format:

  • key: the target, in conjunction with deliveryType.

    • If deliveryType is 1, the key is the Android device ID.

    • If deliveryType is 2, the key is the iOS device ID.

    • If deliveryType is 3, the key is the user ID, which is the userid value passed when the user calls the binding interface.

  • value: the message business ID, user-defined, must be unique.

Note

The push target cannot exceed 10, meaning the targetMsgkey parameter can contain up to 10 key-value pairs.

expiredSeconds

Long

Yes

300

Message validity period, in seconds.

templateName

String

Yes

Test template

Template name, created in the console.

Note

The template name cannot contain commas.

templateKeyValue

String

No

{“money”:”200”,”name”:”John”}

Template parameters, in map format, corresponding to the template specified by templateName. The key is the placeholder name, and the value is the value to be replaced. For example, if the template content is (the placeholder name is between two #) Congratulations #name# on winning #money# yuan.

extendedParams

String

No

{“key1”:”value1”}

Extended parameters, in Map format.

notifyType

String

No

Indicates the message channel type:

  • transparent - MPS self-built channel

  • notify - Default channel

strategyType

Integer

No

1

Push strategy type:

  • 0 - Immediate

  • 1 - Scheduled

  • 2 - Loop

If not filled, the default is 0.

StrategyContent

String

No

{\”fixedTime\”:1630303126000,\”startTime\”:1625673600000,\”endTime\”:1630303126000,\”circleType\”:1,\”circleValue\”:[1, 7],\”time\”:\”13:45:11\”}

Push strategy details (JSON string). Required when strategyType is not equal to 0. For specific parameters, see the StrategyContent field description below.

smsStrategy

int

No

2

SMS strategy:

  • 0 - None (default)

  • 1 - Resend

  • 2 - Concurrent

smsSignName

String

No

mPaaS test

SMS signature

smsTemplateCode

String

No

SMS_216070269

SMS template ID

smsTemplateParam

String

No

{\"code\": 123456}

The actual value corresponding to the SMS template variable, in JSON format.

thirdChannelCategory

Map

No

thirdChannelCategory: {

"hms": "9", //Huawei FINANCE financial type message

"vivo": "1"

//vivo IM type message

}

Used to pass vendor message classification, for details, see Vendor message classification.

notifyLevel

Map

No

notifyLevel: {"oppo":"2"//OPPO notification bar + lock screen}

Vendor message notification level, such as the OPPO message level is as follows:

  • 1 - Notification bar

  • 2 - Notification bar + lock screen

  • 3 - Notification bar + lock screen + banner + vibration + ringtone

miChannelId

String

No

"123321"

Xiaomi vendor push channel channelId

activityEvent

String

No

Real-time activity event, optional update/end:

  • update - Update event

  • end - End event

activityContentState

JSONObject

No

The content-state of real-time activity messages must remain consistent with the parameters defined by the client.

dismissalDate

long

No

Expiration time of the real-time activity message (second-level timestamp), optional field. If not passed, the iOS system defaults to expire after 12 hours.

Note

Regarding the smsStrategy parameter:

  • If the smsStrategy value is not 0, then smsSignName, smsTemplateCode, and smsTemplateParam are mandatory.

Regarding the activityEvent parameter:

  • When activityEvent is the end event, the expiration time set by dismissalDate will be effective.

  • When activityEvent is the update event, the expiration time set by dismissalDate will not be effective.

  • If the end event is specified but dismissalDate is not, the iOS system will default to ending the real-time activity after 4 hours.

StrategyContent field description

Convert JSON format to a String to pass values.

Parameter name

Type

Required

Example

Description

fixedTime

long

No

1630303126000

Scheduled push timestamp (unit: milliseconds, accurate to seconds). When the push policy type is scheduled (strategyType value is 1), fixedTime is required.

startTime

long

No

1640966400000

The timestamp for the start of the loop cycle (unit: milliseconds, accurate to the day). When the push policy type is loop (strategyType value is 2), startTime is required.

endTime

long

No

1672416000000

The timestamp for the end of the loop cycle (unit: milliseconds, accurate to the day). The loop end time must not exceed 180 days after the current day. When the push policy type is loop (strategyType value is 2), endTime is required.

circleType

int

No

3

Loop type:

  • 1 - Daily

  • 2 - Weekly

  • 3 - Monthly

When the push policy type is loop (strategyType value is 2), circleType is required.

circleValue

int[]

No

[1,3]

Loop value:

  • If the loop type is daily: empty.

  • If the loop type is weekly: set the weekly loop time, for example, [1,3] indicates Monday and Wednesday.

  • If the loop type is monthly: set the monthly loop push time, for example, [1,3] indicates the 1st and 3rd of each month.

When the push policy type is loop (strategyType value is 2) and the loop type (circleType) is not daily, circleValue is required.

time

String

No

09:45:11

The loop push time (hours, minutes, and seconds, in the format HH:mm:ss). When the push strategy type is loop (strategyType value is 2), the time is required.

Note
  • By default, the maximum number of unscheduled or loop push tasks that can remain unexecuted is 100.

  • The loop cycle runs from 0:00 of the start date to 24:00 of the end date.

  • The loop start and end times cannot be earlier than 0:00 on the current day, and the end time must not precede the start time.

Return parameters

Parameter name

Type

Example

Description

RequestId

String

B589F4F4-CD68-3CE5-BDA0-6597F33E23916512

Request ID

ResultCode

String

OK

Request result code

ResultMessage

String

param is invalid

Request error description

PushResult

JSON

Request result

Success

boolean

true

Request status. The Success parameter value is included in the PushResult JSON string.

ResultMsg

String

param is invalid

Request error content. The ResultMsg parameter value is included in the PushResult JSON string.

Data

String

903bf653c1b5442b9ba07684767bf9c2

Scheduled push task ID. This field is not empty when strategyType is not equal to 0.

Code examples

Ensure that your AccessKey has the AliyunMPAASFullAccess permission. For details, see Application-level access control for RAM accounts.

Java code example

You can click here to learn how to obtain the AccessKeyId and AccessKeySecret in the following code example.

 DefaultProfile.addEndpoint("cn-hangzhou", "mpaas", "mpaas.cn-hangzhou.aliyuncs.com");
        // Create a DefaultAcsClient instance and initialize
        // The Alibaba Cloud account AccessKey has access to all APIs. It is recommended to use RAM users for API access or daily operations.
        // We strongly recommend that you do not save the AccessKey ID and AccessKey Secret in the project code. Otherwise, the AccessKey may be leaked, compromising the security of all resources in your account.
        // This example demonstrates saving the AccessKey ID and AccessKey Secret in environment variables. You can also save them in configuration files based on your business needs.
        // It is recommended to complete the environment variable configuration first
        String accessKeyId = System.getenv("MPAAS_AK_ENV");
        String accessKeySecret = System.getenv("MPAAS_SK_ENV");
        DefaultProfile profile = DefaultProfile.getProfile(
            "cn-hangzhou",          // Region ID
            accessKeyId,      
            accessKeySecret); 

        IAcsClient client = new DefaultAcsClient(profile);
        // Create an API request and set parameters
        PushTemplateRequest request = new PushTemplateRequest();
        request.setAppId("ONEX570DA89211721");
        request.setWorkspaceId("test");
        request.setTemplateName("Test template");
        //Hello #name#, congratulations on winning #money# yuan
        Map<String,String> templatekv = new HashMap<String, String>();
        templatekv.put("name","John");
        templatekv.put("money","200");
        request.setTemplateKeyValue(JSON.toJSONString(templatekv));
        request.setExpiredSeconds(600L);
        request.setTaskName("Template test");
        request.setDeliveryType(3L);
        Map<String,String> target = new HashMap<String, String>();
        String msgKey = String.valueOf(System.currentTimeMillis());
        target.put("userid1024",msgKey);
        request.setTargetMsgkey(JSON.toJSONString(target));

        request.setStrategyType(2);
        request.setStrategyContent("{\"fixedTime\":1630303126000,\"startTime\":1625673600000,\"endTime\":1630303126000,\"circleType\":1,\"circleValue\":[1, 7],\"time\":\"13:45:11\"}");

        PushTemplateResponse response;
        try {
            response = client.getAcsResponse(request);

            System.out.println(response.getResultCode());
            System.out.println(response.getResultMessage());
        } catch (ClientException e) {
            e.printStackTrace();
        }

Python code example

from aliyunsdkcore.client import AcsClient
from aliyunsdkmpaas.request.v20190821 import PushTemplateRequest
import json
import time

        // The Alibaba Cloud account AccessKey has access to all APIs, which is highly risky. We strongly recommend that you create and use RAM users for API access or daily operations. Please log on to the RAM console to create RAM users
        // This example demonstrates saving the AccessKey and AccessKeySecret in environment variables. You can also save them in configuration files based on your business needs
        // We strongly recommend that you do not save the AccessKey and AccessKeySecret in the code, as there is a risk of key leakage
        // It is recommended to complete the environment variable configuration 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 = PushTemplateRequest.PushTemplateRequest()
request.set_endpoint("mpaas.cn-hangzhou.aliyuncs.com")
request.set_AppId("ONEX570DA89211721")
request.set_WorkspaceId("test")
request.set_TemplateName("template1024")
templatekv = {"name":"John","money":"200"}
request.set_TemplateKeyValue(json.dumps(templatekv))
request.set_DeliveryType(3)
request.set_TaskName("Python template test task")
request.set_ExpiredSeconds(600)
target = {"userid1024":str(time.time())}
request.set_TargetMsgkey(json.dumps(target))

# Print response
response = client.do_action_with_exception(request)
print response

Node.js code example

const sdk = require('@alicloud/mpaas20190821');

const { default: Client, PushTemplateRequest } = sdk;
// Create a client
// The Alibaba Cloud account AccessKey has access to all APIs, which is highly risky. We strongly recommend that you create and use RAM users for API access or daily operations. Please log on to the RAM console to create RAM users
// This example demonstrates saving the AccessKey and AccessKeySecret in environment variables. You can also save them in configuration files based on your business needs
// We strongly recommend that you do not save the AccessKey and AccessKeySecret in the code, as there is a risk of key leakage
// It is recommended to complete the environment variable configuration 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 PushTemplateRequest();
  request.appId = "ONEX570DA89211721";
  request.workspaceId = "test";
  request.templateName= "template1024";
  const templatekv = {
    name: 'John',
    money:'300'
  };
  request.templateKeyValue = JSON.stringify(templatekv);
  request.deliveryType = 3;
  request.taskName = "Node test task";
  request.expiredSeconds=600;
  const extendedParam = {
    test: 'Custom extended parameter'
  };
  request.extendedParams = JSON.stringify(extendedParam);
  const target = {
    "userid1024": String(new Date().valueOf())
  };
  request.targetMsgkey = JSON.stringify(target);

// Call API
try {
  client.pushTemplate(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->templatePush();
        } catch (\Exception $e) {
        }
    }

    public function templatePush() {
        $request = MPaaS::v20190821()->pushTemplate();
        $result = $request->host("mpaas.cn-hangzhou.aliyuncs.com")
            // Enable debug mode
            ->debug(true)
            ->withAppId("ONEX570DA89211721")
            ->withWorkspaceId("test")
            ->withTemplateName("template1024")
            ->withTemplateKeyValue(json_encode(["name" => "John", "money" => "200"]))
            ->withDeliveryType(3)
            ->withTaskName("PHP test task")
            ->withExpiredSeconds(600)
            ->withTargetMsgkey(
                json_encode(["userid1024" => "".time() ])
            )
            ->request();
    }
}