# Get a list of existing templates

Debugging Tools

Interface should be called on the server side, not in the front end (Weixin Mini Program, web pages, APP, etc.) directly called, specific reference interface call guide

Interface name: getwxapubnewtemplate

This interface is used to obtain a list of existing templates under the current account.

# 1. How to call

# HTTPS calls

GET https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token=ACCESS_TOKEN

# Cloud Calls

  • Call method: subscribeMessage.getTemplateList

  • The input and exit parameters are the same as the HTTPS call, which can be called in the cloud call documentation

# Third party invocation

  • This interface supports Third Party Platform generation business call.

  • This interface belongs to the permission set id: 18,89

  • When a service provider is authorized by one of the permissions set, it can call on behalf of the merchant by using authorizer_access_token , which can be viewed in the third-party call documentation.

# 2. Request parameters

# Query parametersQuery String parameters

Parameter NametypeRequired to fill inIntroductions
access_tokenstringyesInterface invocation credentials, using access_token , authorizer_access_token

# Request BodyRequest Payload

nothing

# 3. Return Parameters

# Response Payload

Parameter NametypeIntroductions
errcodenumberError code
errmsgstringError message
dataobjarrayList of templates

# Res.data(Array)Object Payload

List of templates

Parameter NametypeIntroductions
priTmplIdstringAdded to the template id under account, required to send Weixin Mini Program subscription message
titlestringThe template title
contentstringModel content
examplestringExamples of Template Content
typenumberType of template, 2 for a one-time subscription, 3 for a long-term subscription
keywordEnumValueListobjarrayThe range of enumerable parameter values

# Res.data(Array).keywordEnumValueListObject Payload

The range of enumerable parameter values

Parameter NametypeIntroductions
keywordCodestringKey for enumeration parameters
enumValueListarrayList of enumerable parameter value ranges

# 4. Note

There are no special considerations for this interface

# 5. Code examples

# 5.1 Sample HTTPS Request

Example Requests

GET https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token=ACCESS_TOKEN

Return an example

{
  "errcode": 0,
  "errmsg": "ok",
  "data": [
    {
      "priTmplId": "9Aw5ZV1j9xdWTFEkqCpZ7mIBbSC34khK55OtzUPl0rU",
      "title": "报名结果通知",
      "content": "会议时间:{{date2.DATA}}\n会议地点:{{thing1.DATA}}\n",
      "example": "会议时间:2016年8月8日\n会议地点:TIT会议室\n",
      "type": 2
    },
    {
      "priTmplId": "cy_DfOZL7lypxHh3ja3DyAUbn1GYQRGwezuy5LBTFME",
      "title": "洗衣机故障提醒",
      "content": "完成时间:{{time1.DATA}}\n所在位置:{{enum_string2.DATA}}\n提示说明:{{enum_string3.DATA}}\n",
      "example": "完成时间:2021年10月21日 12:00:00\n所在位置:客厅\n提示说明:设备发生故障,导致工作异常,请及时查看\n",
      "keywordEnumValueList": [
        {
          "enumValueList": [
            "客厅",
            "餐厅",
            "厨房",
            "卧室",
            "主卧",
            "次卧",
            "客卧",
            "父母房",
            "儿童房",
            "男孩房",
            "女孩房",
            "卫生间",
            "主卧卫生间",
            "公共卫生间",
            "衣帽间",
            "书房",
            "游戏室",
            "阳台",
            "地下室",
            "储物间",
            "车库",
            "保姆房",
            "其他房间"
          ],
          "keywordCode": "enum_string2.DATA"
        },
        {
          "enumValueList": [
            "设备发生故障,导致工作异常,请及时查看"
          ],
          "keywordCode": "enum_string3.DATA"
        }
      ],
      "type": 3
    }
  ]
}

# 5.2 Cloud function call example

Example Requests

const cloud = require('wx-server-sdk')
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV,
})
exports.main = async (event, context) => {
  try {
    const result = await cloud.openapi.subscribeMessage.getTemplateList({})
    return result
  } catch (err) {
    return err
  }
}

Return an example

{
  "errCode": 0,
  "errMsg": "openapi.subscribeMessage.getTemplateList:ok",
  "data": [
    {
      "priTmplId": "9Aw5ZV1j9xdWTFEkqCpZ7mIBbSC34khK55OtzUPl0rU",
      "title": "报名结果通知",
      "content": "会议时间:{{date2.DATA}}\n会议地点:{{thing1.DATA}}\n",
      "example": "会议时间:2016年8月8日\n会议地点:TIT会议室\n",
      "type": 2
    },
    {
      "priTmplId": "cy_DfOZL7lypxHh3ja3DyAUbn1GYQRGwezuy5LBTFME",
      "title": "洗衣机故障提醒",
      "content": "完成时间:{{time1.DATA}}\n所在位置:{{enum_string2.DATA}}\n提示说明:{{enum_string3.DATA}}\n",
      "example": "完成时间:2021年10月21日 12:00:00\n所在位置:客厅\n提示说明:设备发生故障,导致工作异常,请及时查看\n",
      "keywordEnumValueList": [
        {
          "enumValueList": [
            "客厅",
            "餐厅",
            "厨房",
            "卧室",
            "主卧",
            "次卧",
            "客卧",
            "父母房",
            "儿童房",
            "男孩房",
            "女孩房",
            "卫生间",
            "主卧卫生间",
            "公共卫生间",
            "衣帽间",
            "书房",
            "游戏室",
            "阳台",
            "地下室",
            "储物间",
            "车库",
            "保姆房",
            "其他房间"
          ],
          "keywordCode": "enum_string2.DATA"
        },
        {
          "enumValueList": [
            "设备发生故障,导致工作异常,请及时查看"
          ],
          "keywordCode": "enum_string3.DATA"
        }
      ],
      "type": 3
    }
  ]
}

# 6. Error code

The following is a list of error codes for this interface, other error codes can refer to General error codes

Error codeError DescriptionSolutions
-1system errorThe system is busy, so the developer is asked to try again in a few minutes.
404404 not foundPlease check if the calling method is incorrect [get | post]
40001invalid credential  access_token isinvalid or not latestAppSecret error while getting access_token, or access_token is invalid.Developers should check that AppSecret is correct, or that they are calling interfaces for the appropriate Official Account
200100The type of account is not legal.Please use the Weixin Mini Program account to call

# 7. Scope of application

How this interface can be invoked under different account types:
Weixin Mini Program Official Account Service Account MiniGame
Certification only Certification only
  • ✔: The account can call this interface
  • Authentication only: means that only authenticated accounts are allowed to be invoked by the enterprise entity, and accounts that are not authenticated or do not support authentication cannot be invoked.
  • Other account types that are not expressly stated may not be called on this interface without special instructions;