The following APIs are provided to help third-party developers set templates for the Mini Program template message API, making it easier for third-party developers to send template messages:
1. Obtaining the Title List from a Mini Program Template Library
API Instructions
POST https://api.weixin.qq.com/cgi-bin/wxopen/template/library/list?access_token=ACCESS_TOKEN
POST data example:
{
"offset": 0,
"count": 5
}
Parameters
| Parameter | Required | Description |
|---|---|---|
| access_token | Yes | API call credential |
| offset | Yes | The offset and count fields are used for paging. It indicates "count" records are pulled starting from "offset." The offset field starts from 0, and the maximum value of the count field is 20. |
| count | Yes | The offset and count fields are used for paging. It indicates "count" records are pulled starting from "offset." The offset field starts from 0, and the maximum value of the count field is 20. |
Example of return result for a successful call:
{
"errcode": 0,
"errmsg": "ok",
"list": [
{ "id": "AT0002", "title": "Purchase success notification" },
{ "id": "AT0003", "title": "Purchase failure notification" },
{ "id": "AT0004", "title": "Transaction reminder" },
{ "id": "AT0005", "title": "Payment success notification" },
{ "id": "AT0006", "title": "Payment failure notification" }
],
"total_count": 599
}
Parameters
| Parameter | Description |
|---|---|
| id | The ID of the template title. It is required when the keyword library under the template title is to be obtained. |
| title | The content of the template title |
| total_count | The quantity of titles in the template library |
2. Obtaining a Keyword Library Under a Template Title from the Template Library
API Instructions
POST https://api.weixin.qq.com/cgi-bin/wxopen/template/library/get?access_token=ACCESS_TOKEN
POST data example:
{
"id": "AT0002"
}
Parameters
| Parameter | Required | Description |
|---|---|---|
| access_token | Yes | API call credential |
| id | Yes | The ID of the template title. It can be obtained via the API or the Mini Program backend. |
Example of return result for a successful call:
{
"errcode": 0,
"errmsg": "ok",
"id": "AT0002",
"title": "Purchase success notification",
"keyword_list": [
{
"keyword_id": 3,
"name": "Purchase location",
"example": "TITShipbuilding factory"
},
{
"keyword_id": 4,
"name": "Purchase time",
"example": "2016-6-6"
},
{
"keyword_id": 5,
"name": "Item name",
"example": "Coffee"
}
]
}
Parameters
| Parameter | Description |
|---|---|
| keyword_id | The ID of the keyword. It is required when a template is added. |
| name | The content of the keyword |
| example | An example of the keyword's content |
3. Grouping Templates and Adding Them to the Personal Template Library of an Account
API Instructions
POST https://api.weixin.qq.com/cgi-bin/wxopen/template/add?access_token=ACCESS_TOKEN
POST data example:
{
"id": "AT0002",
"keyword_id_list": [3, 4, 5]
}
Parameters
| Parameter | Required | Description |
|---|---|---|
| access_token | Yes | API call credential |
| id | Yes | The ID of the template title |
| keyword_id_list | 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 combined. |
Example of return result for a successful call:
{
"errcode": 0,
"errmsg": "ok",
"template_id": "wDYzYZVxobJivW9oMpSCpuvACOfJXQIoKUm0PY397Tc"
}
Parameters
| Parameter | Description |
|---|---|
| template_id | The template ID to be added to the account. It is required when a Mini Program's message template is to be sent. |
The following APIs are provided to help third-party developers work with the existing templates under an account:
1. Obtaining the List of Existing Templates Under an Account
API Instructions
POST https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token=ACCESS_TOKEN
POST data example:
{
"offset": 0,
"count": 1
}
Parameters
| Parameter | Required | Description |
|---|---|---|
| access_token | Yes | API call credential |
| offset | Yes | The offset and count fields are used for paging. It indicates "count" records are pulled starting from "offset." The offset field starts from 0, and the maximum value of the count field is 20. The list on the last page may be less than the count in the request. |
| count | Yes | The offset and count fields are used for paging. It indicates "count" records are pulled starting from "offset." The offset field starts from 0, and the maximum value of the count field is 20. The list on the last page may be less than the count in the request. |
Example of return result for a successful call:
{
"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"
}
]
}
Parameters
| Parameter | Description |
|---|---|
| list | A list of templates under an account |
| template_id | The ID of the template. It is required when a Mini Program's message template is to be sent. |
| title | The title of the template |
| content | The content of the template |
| example | An example of the template content |
2. Deleting a Template from an Account
API Instructions
POST https://api.weixin.qq.com/cgi-bin/wxopen/template/del?access_token=ACCESS_TOKEN
POST data example:
{
"template_id": "wDYzYZVxobJivW9oMpSCpuvACOfJXQIoKUm0PY397Tc"
}
Parameters
| Parameter | Required | Description |
|---|---|---|
| access_token | Yes | API call credential |
| template_id | Yes | The ID of the template to be deleted |
Example of return result for a successful call:
{
"errcode": 0,
"errmsg": "ok"
}
For more information on the API for sending template messages, see templateMessage.send.