Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat Gadget Subscribe to Message GetTemplateList


May 20, 2021 WeChat Mini Program Development Document


Table of contents


subscribeMessage.getTemplateList

This interface should be called on the server side, as detailed in the Service Side API.
This interface supports cloud calls. Developer tool version required . . . 1.02.1904090 (latest stable download)
wx-server-sdk >= 0.4.0

Get a list of personal templates under your current account

How to call:

  • HTTPS call
  • Cloud calls

HTTPS call

The request address

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

Request parameters

Property Type The default Required Description
access_token string Is The interface calls the credentials

Returns a value

Object

The returned JSON packet

Property Type Description
errcode number Error code
errmsg string The error message
data Array.<Object> A list of personal templates

The structure of the data

Property Type Description
priTmplId string Add to the template id under your account to send the applet subscription messages you need
title string The template title
content string Template content
example string Example of template content
type number Template type, 2 is a one-time subscription and 3 is a long-term subscription

An example response

{
   "errcode": 0,
   "errmsg": "ok",
   "data": [
       {
          "priTmplId": "9Aw5ZV1j9xdWTFEkqCpZ7mIBbSC34khK55OtzUPl0rU",
          "title": "报名结果通知",
          "content": "会议时间:{{date2.DATA}}\n会议地点:{{thing1.DATA}}\n",
          "example": "会议时间:2016年8月8日\n会议地点:TIT会议室\n",
          "type": 2
       }
   ]
}

Cloud calls

Cloud call is the ability provided by the small program Cloud Development to call WeChat open interfaces in cloud functions and need to be used in cloud functions via wx-server-sdk.

The interface method

openapi.subscribeMessage.getTemplateList
Permissions for the subscribeMessage.getTemplateList API need to be configured in config.json, details

Returns a value

Object

The returned JSON packet

Property Type Description
errCode number Error code
errMsg string The error message
data Array.<Object> A list of personal templates

The structure of the data

Property Type Description
priTmplId string Add to the template id under your account to send the applet subscription messages you need
title string The template title
content string Template content
example string Example of template content
type number Template type, 2 is a one-time subscription and 3 is a long-term subscription

Abnormal

Object

The exception thrown

Property Type Description
errCode number Error code
errMsg string The error message

The legal value of errCode

Value Description The lowest version

An example of a request

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

An example response

const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
  try {
    const result = await cloud.openapi.subscribeMessage.getTemplateList({
        errcode: 0,
        errmsg: 'ok',
        data: [
          {
            priTmplId: '9Aw5ZV1j9xdWTFEkqCpZ7mIBbSC34khK55OtzUPl0rU',
            title: '报名结果通知',
            content: '会议时间:{{date2.DATA}}\n会议地点:{{thing1.DATA}}\n',
            example: '会议时间:2016年8月8日\n会议地点:TIT会议室\n',
            type: 2
          }
        ]
      })
    return result
  } catch (err) {
    return err
  }
}