Use the message template APIs to create, delete, and query push notification templates for your mPaaS application.
Common fields
Input parameters
|
Parameter |
Type |
Required |
Example |
Description |
|
appId |
String |
Yes |
ONEX570DA89211721 |
The application ID. |
|
workspaceId |
String |
Yes |
default |
The workspace ID. |
|
tenantId |
String |
Yes |
LZFPEFIM |
The tenant ID. |
Output parameters
|
Parameter |
Type |
Example |
Description |
|
requestId |
String |
B589F4F4-CD68-3CE5-BDA0-6597F33E23916512 |
The request ID. |
|
success |
boolean |
true |
Indicates whether the request was successful. |
|
code |
String |
100 |
The result code. |
|
msg |
String |
SUCCESS |
The result message. |
|
data |
Object |
- |
The result content. |
|
currentPage |
int |
1 |
The current page number. |
|
pageSize |
int |
100 |
The number of records per page. |
|
totalSize |
int |
80 |
The total number of records. |
-
For the create, delete, paged query, and single query APIs, the response data is returned in the `Data` field.
-
Only the paged query API includes the currentPage, pageSize, and totalSize parameters.
Result codes
|
Result code |
Result message |
Description |
|
100 |
SUCCESS |
Success. |
|
3022 |
TEMPLATE_NOT_EXIST |
The template does not exist. |
|
3028 |
INVALID_PARAM |
Check the parameters. |
|
3036 |
TEMPLATE_ALREADY_EXIST |
The template already exists. |
|
8011 |
FLOW_CONTROL_ERROR |
Throttling. |
|
8012 |
INVALID_INSTANCE_ID |
Check the AppID and WorkspaceID. |
|
8013 |
INVALID_TENANT_ID |
Invalid TenantID. |
|
8014 |
ACCOUNT_NO_PERMISSION |
No permission. |
|
9000 |
SYSTEM_ERROR |
System error. |
Create a template
Each app supports a maximum of 100 templates.
Input parameters
|
Parameter |
Type |
Required |
Example |
Description |
|
templateName |
String |
Yes |
TestTemplate |
The template name. You must create the template in the console. Note
The template name cannot contain commas. |
|
descInfo |
String |
Yes |
Template description |
The template description. |
|
title |
String |
Yes |
Template title |
The template title. If the title is a placeholder, wrap it in |
|
content |
String |
Yes |
Template content |
The template content. If the value is a placeholder, enclose it in |
|
uri |
String |
No |
|
The redirection URL. |
|
variables |
String |
No |
|
The placeholder fields. Separate multiple fields with commas. |
|
showStyle |
long |
No |
0 |
Whether to use silence mode.
|
|
imageUrls |
String |
No |
|
The URL of the large image when |
|
iconUrls |
String |
No |
|
The URL of the icon when |
|
pushStyle |
int |
No |
0 |
The display style.
|
|
jumpAction |
int |
No |
0 |
The action after a click.
|
Output parameters
|
Data |
|||
|
Parameter |
Type |
Example |
Description |
|
data |
String |
8346 |
The template ID. |
Examples
import com.alibaba.fastjson.JSON;
import com.aliyun.mpaas20201028.Client;
import com.aliyun.mpaas20201028.models.CreateTemplateRequest;
import com.aliyun.mpaas20201028.models.CreateTemplateResponse;
import com.aliyun.teaopenapi.models.Config;
public static void main(String[] args) throws Exception {
// An Alibaba Cloud account AccessKey has full permissions for 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. This example uses the China (Hangzhou) region.
config.setRegionId("cn-hangzhou");
config.setEndpoint("mpaas.cn-hangzhou.aliyuncs.com");
Client client = new Client(config);
CreateTemplateRequest request = new CreateTemplateRequest();
request.setAppId("ONEX570DA89211721");
request.setWorkspaceId("test");
request.setTenantId("xxx");
request.setTemplateName("CreateTestTemplate");
request.setContent("Test template content");
request.setTitle("Test template title");
request.setDescInfo("Test template description");
CreateTemplateResponse response = client.createTemplate(request);
System.out.println("response==>"+JSON.toJSONString(response));
}
Delete a template
Input parameters
|
Parameter |
Type |
Required |
Example |
Description |
|
templateId |
String |
No |
8346 |
Specify either |
|
templateName |
String |
No |
Test |
Specify either |
Output parameters
The Data field is null.
Examples
import com.alibaba.fastjson.JSON;
import com.aliyun.mpaas20201028.Client;
import com.aliyun.mpaas20201028.models.DeleteTemplateRequest;
import com.aliyun.mpaas20201028.models.DeleteTemplateResponse;
import com.aliyun.teaopenapi.models.Config;
public static void main(String[] args) throws Exception {
// An Alibaba Cloud account AccessKey has full permissions for 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. This example uses the China (Hangzhou) region.
config.setRegionId("cn-hangzhou");
config.setEndpoint("mpaas.cn-hangzhou.aliyuncs.com");
Client client = new Client(config);
DeleteTemplateRequest request = new DeleteTemplateRequest();
request.setAppId("ONEX570DA89211721");
request.setWorkspaceId("test");
request.setTenantId("xxx");
request.setTemplateName("CreateTestTemplate");
DeleteTemplateResponse response = client.deleteTemplate(request);
System.out.println("response==>"+JSON.toJSONString(response));
}
Paged query
Input parameters
|
Parameter |
Type |
Required |
Example |
Description |
|
currentPage |
int |
No |
1 |
The page number. Default value: 1. |
|
pageSize |
int |
No |
100 |
The number of records per page. Default value: 100. |
Output parameters
The Data type is List<Template>.
|
Template |
|||
|
Parameter |
Type |
Example |
Description |
|
id |
String |
8346 |
The template ID. |
|
name |
String |
Test |
The template name. |
|
descInfo |
String |
Template description |
The template description. |
|
title |
String |
Template title |
The title. |
|
content |
String |
Template content |
The content. |
|
uri |
String |
|
The redirection URL. |
|
variables |
String |
|
The placeholder fields. |
|
showStyle |
String |
0 |
Indicates whether silence mode is used. |
|
imageUrls |
String |
|
The large image URL. |
|
iconUrls |
String |
|
The icon URL. |
|
pushStyle |
String |
0 |
The display style. |
|
action |
String |
0 |
The action type after a click. |
|
gmtCreate |
String |
1587376706000 |
The creation time. |
|
gmtModified |
String |
1587376706000 |
The modification time. |
Examples
import com.alibaba.fastjson.JSON;
import com.aliyun.mpaas20201028.Client;
import com.aliyun.mpaas20201028.models.ListTemplatePageRequest;
import com.aliyun.mpaas20201028.models.ListTemplatePageResponse;
import com.aliyun.teaopenapi.models.Config;
public static void main(String[] args) throws Exception {
// An Alibaba Cloud account AccessKey has full permissions for 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. This example uses the China (Hangzhou) region.
config.setRegionId("cn-hangzhou");
config.setEndpoint("mpaas.cn-hangzhou.aliyuncs.com");
Client client = new Client(config);
ListTemplatePageRequest request = new ListTemplatePageRequest();
request.setAppId("ONEX570DA89211721");
request.setWorkspaceId("test");
request.setTenantId("xxx");
request.setCurrentPage(1);
request.setPageSize(2);
ListTemplatePageResponse response = client.listTemplatePage(request);
System.out.println("response==>"+JSON.toJSONString(response));
}
Single query
Input parameters
|
Parameter |
Type |
Required |
Example |
Description |
|
templateId |
String |
No |
8346 |
Specify either |
|
templateName |
String |
No |
Test |
Specify either |
Output parameters
The Data type is Template.
|
Template |
|||
|
Parameter |
Type |
Example |
Description |
|
id |
String |
8346 |
The template ID. |
|
name |
String |
Test |
The template name. |
|
descInfo |
String |
Template description |
The template description. |
|
title |
String |
Template title |
The title. |
|
content |
String |
Template content |
The content. |
|
uri |
String |
|
The redirection URL. |
|
variables |
String |
|
The placeholder fields. |
|
showStyle |
String |
0 |
Indicates whether silence mode is used. |
|
imageUrls |
String |
|
The large image URL. |
|
iconUrls |
String |
|
The icon URL. |
|
pushStyle |
String |
0 |
The display style. |
|
action |
String |
0 |
The action type after a click. |
|
gmtCreate |
String |
1587376706000 |
The creation time. |
|
gmtModified |
String |
1587376706000 |
The modification time. |
Examples
import com.alibaba.fastjson.JSON;
import com.aliyun.mpaas20201028.Client;
import com.aliyun.mpaas20201028.models.GetTemplateRequest;
import com.aliyun.mpaas20201028.models.GetTemplateResponse;
import com.aliyun.teaopenapi.models.Config;
public static void main(String[] args) throws Exception {
// An Alibaba Cloud account AccessKey has full permissions for 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. This example uses the China (Hangzhou) region.
config.setRegionId("cn-hangzhou");
config.setEndpoint("mpaas.cn-hangzhou.aliyuncs.com");
Client client = new Client(config);
GetTemplateRequest request = new GetTemplateRequest();
request.setAppId("ONEX570DA89211721");
request.setWorkspaceId("test");
request.setTenantId("xxx");
request.setTemplateName("TestTemplate");
GetTemplateResponse response = client.getTemplate(request);
System.out.println("response==>"+JSON.toJSONString(response));
}