# templateMessage.addTemplate
Call this API at the server side. For more information, see Server API.
This API supports Cloud Calls. The WeChat DevTools version must be
1.02.1904090or later (download the latest stable version here), and thewx-server-sdkversion must be0.4.0or later.
Groups templates and adds to the personal template library in the account.
Calling methods:
# HTTPS Call
# Request Address
POST https://api.weixin.qq.com/cgi-bin/wxopen/template/add?access_token=ACCESS_TOKEN
# Request Parameters
| Attribute | Type | Default | Required | Description |
|---|---|---|---|---|
| access_token | string | Yes | Credentials to call API | |
| id | string | Yes | The ID of the template title. It can be obtained via the API or the Mini Program backend. | |
| keyword_id_list | Array.<number> | Yes | The list of template keywords grouped by developers. The keywords can be grouped in a random sequence (for example, [3,5,4] or [4,5,3]). A maximum of 10 keywords can be grouped. |
# Return Value
# Object
JSON data package that is returned
| Attribute | Type | Description |
|---|---|---|
| errcode | number | Error code |
| errmsg | string | Error message |
| template_id | string | The template ID to be added to the account. It is required when a Mini Program's template message is to be sent. |
# Request Data Example
{
"id":"AT0002",
"keyword_id_list":[3,4,5]
}
# Return Data Example
{
"errcode": 0,
"errmsg": "ok",
"template_id": "wDYzYZVxobJivW9oMpSCpuvACOfJXQIoKUm0PY397Tc"
}
# Cloud Call
Cloud call is a capability provided by Mini Program·Cloud Base that allows you to call WeChat APIs in a cloud function. It must be used via
wx-server-sdkin the cloud function.
# API Calling Method
openapi.templateMessage.addTemplate
You need to configure the permissions for the
templateMessage.addTemplateAPI viaconfig.json. Details
# Request Parameters
| Attribute | Type | Default | Required | Description |
|---|---|---|---|---|
| id | string | Yes | The ID of the template title. It can be obtained via the API or the Mini Program backend. | |
| keywordIdList | Array.<number> | Yes | The list of template keywords grouped by developers. The keywords can be grouped in a random sequence (for example, [3,5,4] or [4,5,3]). A maximum of 10 keywords can be grouped. |
# Return Value
# Object
JSON data package that is returned
| Attribute | Type | Description |
|---|---|---|
| errCode | number | Error code |
| errMsg | string | Error message |
| templateId | string | The template ID to be added to the account. It is required when a Mini Program's template message is to be sent. |
# Exceptions
# Object
Thrown Exceptions
| Property | Type | Description |
|---|---|---|
| errCode | number | Error code |
| errMsg | string | Error message |
Valid values of errCode
| Value | Description | Minimum Version |
|---|
# Request Data Example
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.templateMessage.addTemplate({
id: 'AT0002',
keywordIdList: [
3,
4,
5
]
})
console.log(result)
return result
} catch (err) {
console.log(err)
return err
}
}
# Return Data Example
{
"errCode": 0,
"errMsg": "openapi.templateMessage.addTemplate:ok",
"templateId": "wDYzYZVxobJivW9oMpSCpuvACOfJXQIoKUm0PY397Tc"
}