# Get Categories
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: getCategory
This interface is used to get Weixin Mini Program, Official Account belongs to the category for query public template
# 1. How to call
# HTTPS calls
GET https://api.weixin.qq.com/wxaapi/newtmpl/getcategory?access_token=ACCESS_TOKEN
# Cloud Calls
Call method: subscribeMessage.getCategory
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 Name | type | Required to fill in | Introductions |
---|---|---|---|
access_token | string | yes | Interface invocation credentials, using access_token , authorizer_access_token |
# Request BodyRequest Payload
nothing
# 3. Return Parameters
# Response Payload
Parameter Name | type | Introductions |
---|---|---|
errcode | number | Error code |
errmsg | string | Error message |
data | objarray | List of categories |
# Res.data(Array)Object Payload
List of categories
Parameter Name | type | Introductions |
---|---|---|
id | number | Category id, you need to query the public template library |
name | string | Chinese name of category |
# 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/getcategory?access_token=ACCESS_TOKEN
Return an example
{
"errcode": 0,
"errmsg": "ok",
"data": [
{
"id": 616,
"name": "公交"
}
]
}
# 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.getCategory({})
return result
} catch (err) {
return err
}
}
Return an example
{
"errCode": 0,
"errMsg": "openapi.subscribeMessage.getCategory:ok",
"data": [
{
"id": 616,
"name": "公交"
}
]
}
# 6. Error code
The following is a list of error codes for this interface, other error codes can refer to General error codes
Error code | Error Description | Solutions |
---|---|---|
404 | 404 not found | Please check if the calling method is incorrect [get | post] |
20001 | A system error | undefined |
40001 | invalid credential access_token isinvalid or not latest | AppSecret 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 |
200100 | The type of account is not legal. | Please use the Weixin Mini Program account to call |
# 7. Scope of application
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;