# templateMessage.getTemplateList
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.
Obtains the existing template list under the account.
Calling methods:
# HTTPS Call
# Request Address
POST https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token=ACCESS_TOKEN
# Request Parameters
| Attribute | Type | Default | Required | Description |
|---|---|---|---|---|
| access_token | string | Yes | Credentials to call API | |
| offset | number | Yes | Used for paging. It indicates that each page starts from "offset". Pages are counted from "0". | |
| count | number | Yes | Used for paging. It indicates that "count" records are fetched. Its maximum value is "20". The length of the list on the last page may be less than the value of count in the request. |
# Return Value
# Object
JSON data package that is returned
| Attribute | Type | Description |
|---|---|---|
| errcode | number | Error code |
| errmsg | string | Error message |
| list | Array.<Object> |
list is composed as follows
| Property | Type | Description |
|---|---|---|
| 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. |
| title | string | The title of the template. |
| content | string | The content of the template. |
| example | string | An example of the template content. |
# Request Data Example
{
"offset": 0,
"count": 1
}
# Return Data Example
{
"errcode": 0,
"errmsg": "ok",
"list": [
{
"template_id": "wDYzYZVxobJivW9oMpSCpuvACOfJXQIoKUm0PY397Tc",
"title": "Purchase success notification",
"content": "Purchase location{{keyword1.DATA}}\nPurchase time{{keyword2.DATA}}\nItem name{{keyword3.DATA}}\n",
"example": "Purchase location: TITShipbuilding factory\nPurchase time: 2016-6-6\nItem name: Coffee\n"
}
]
}
# 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.getTemplateList
You need to configure the permissions for the
templateMessage.getTemplateListAPI viaconfig.json. Details
# Request Parameters
| Attribute | Type | Default | Required | Description |
|---|---|---|---|---|
| offset | number | Yes | Used for paging. It indicates that each page starts from "offset". Pages are counted from "0". | |
| count | number | Yes | Used for paging. It indicates that "count" records are fetched. Its maximum value is "20". The length of the list on the last page may be less than the value of count in the request. |
# Return Value
# Object
JSON data package that is returned
| Attribute | Type | Description |
|---|---|---|
| errCode | number | Error code |
| errMsg | string | Error message |
| list | Array.<Object> |
list is composed as follows
| Property | Type | Description |
|---|---|---|
| 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. |
| title | string | The title of the template. |
| content | string | The content of the template. |
| example | string | An example of the template content. |
# 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.getTemplateList({
offset: 0,
count: 1
})
console.log(result)
return result
} catch (err) {
console.log(err)
return err
}
}
# Return Data Example
{
"errCode": 0,
"errMsg": "openapi.templateMessage.getTemplateList:ok",
"list": [
{
"title": "Purchase success notification",
"content": "Purchase location{{keyword1.DATA}}\nPurchase time{{keyword2.DATA}}\nItem name{{keyword3.DATA}}\n",
"example": "Purchase location: TITShipbuilding factory\nPurchase time: 2016-6-6\nItem name: Coffee\n",
"templateId": "wDYzYZVxobJivW9oMpSCpuvACOfJXQIoKUm0PY397Tc"
}
]
}