# Create personalized menus
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: addConditionalMenu
In order to help Official Account achieve flexible business operation, WeChat has added a personalized menu interface to the public platform. Developers can use this interface to let different user groups of the Official Account message template to see different custom menus.
Developers can set the menus that users see by following conditions:
- User tags (developer's business needs can be accomplished with user tags)
- The default menu and all personalized menu information can be obtained using the normal custom menu query interface, see the instructions for the custom menu Query Interface.
- You can delete all custom menus (including the default menu and all personalized menus) using the normal custom menu removal interface. See the instructions for the custom menu reduction interface.
Note: To protect personal privacy, the Official Account personalization menu will no longer support the filtering of information related to personal privacy data such as gender, region, and language, as follows:
- When created, any matching condition that contains private messaging will be rejected and the error code 65320 will be returned;
- Those that have been created automatically expire if they contain private messages, and those that do not are matched normally;
- Developers can still get the menus that fans see through the test interface normally.
- When querying the personalized menu, all rules appear normally.
# 1. How to call
# HTTPS calls
POST https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=ACCESS_TOKEN
# Cloud Calls
Call method: officialAccount.menu.addConditional
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.
The permission set id to which the interface belongs is: 15
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 | Example | Introductions |
---|---|---|---|---|
access_token | string | yes | ACCESS_TOKEN | Interface invocation credentials, using access_token , authorizer_access_token |
# Request BodyRequest Payload
Parameter Name | type | Required to fill in | Introductions |
---|---|---|---|
button | objarray | yes | Level 1 menu array (1 to 3 items) |
matchrule | object | yes | Menu Match Rules (at least one non-empty field) |
# Body.button(Array)Object Payload
Level 1 menu array (1 to 3 items)
Parameter Name | type | Required to fill in | Example | Introductions | to enumerate |
---|---|---|---|---|---|
type | string | no | click | Response action type of menu (exclusive of sub_button) | click view scancode_push scancode_waitmsg pic_sysphoto pic_photo_or_album pic_weixin location_select media_id article_id article_view_limited |
name | string | yes | Songs of the day | Menu title, no more than 16 bytes, submenu no more than 60 bytes | - |
key | string | no | - | The menu KEY value, used for message interface push, does not exceed 128 bytes. Click, etc. Click types must be. | - |
url | string | no | - | Web links, which users can open by clicking on a menu, are no more than 1024 bytes.When type is miniprogram, older versions of the Portals that do not support Weixin Mini Program will open this url.View, miniprogram types are required. | - |
media_id | string | no | - | The valid media_id returned by calling the new permanent material interface. The media_id type and the view_limited type must | - |
appid | string | no | - | Weixin Mini Program of AppID (only Official Account can be configured), the miniprogram type must | - |
pagepath | string | no | - | The page path of Weixin Mini Program, the miniprogram type must | - |
article_id | string | no | - | The legal article_id, article_id type, and article_view_limited type obtained after publication must be | - |
sub_button | objarray | no | - | Array of secondary menu structures | - |
# Body.matchruleObject Payload
Menu Match Rules (at least one non-empty field)
Parameter Name | type | Required to fill in | Example | Introductions |
---|---|---|---|---|
tag_id | string | no | - | The id of the user tag, which can be obtained through the user tag management interface |
client_platform_type | string | no | 1 | Customer version, the current only specific to the system model: IOS (1), Android (2), Others (3), do not fill, do not match |
# Body.button(Array).sub_buttonObject Payload
Array of secondary menu structures
Parameter Name | type | Required to fill in | Example | Introductions |
---|---|---|---|---|
type | string | yes | click | The response action type of the menu (type of the same level menu) |
name | string | yes | Songs of the day | Menu title, no more than 16 bytes, submenu no more than 60 bytes |
key | string | no | - | The menu KEY value, used for message interface push, does not exceed 128 bytes. Click, etc. Click types must be. |
url | string | no | - | Web links, which users can open by clicking on a menu, are no more than 1024 bytes.When type is miniprogram, older versions of the Portals that do not support Weixin Mini Program will open this url.View, miniprogram types are required. |
media_id | string | no | - | The valid media_id returned by calling the new permanent material interface. The media_id type and the view_limited type must |
appid | string | no | - | Weixin Mini Program of AppID (only Official Account can be configured), the miniprogram type must |
pagepath | string | no | - | The page path of Weixin Mini Program, the miniprogram type must |
article_id | string | no | - | The legal article_id, article_id type, and article_view_limited type obtained after publication must be |
# 3. Return Parameters
# Response Payload
Parameter Name | type | Example | Introductions |
---|---|---|---|
menuid | string | 208379533 | Menu ID |
errcode | number | - | Error code |
errmsg | string | - | Error Description |
# 4. Note
- Personalized menu requires the user's WeChat account version in iPhone 6.2.2, Android 6.2.4 above, temporarily do not support other versions WeChat
- The menu refresh strategy is, when the user enters the Official Account session page or Official Account Profile page, if the last request to pull the menu 5 minutes ago, will pull the menu, if the menu has been updated, will refresh the client menu.During the test, you can try to unfollow the public account and follow it again, and you can see the effect of the creation.
- Ordinary Official Account personalized menu of the new interface daily limit of 2000 times, delete the interface is 2000 times, test personalized menu matching results interface for 20000 times
- For security reasons, a Official Account for all personalized menus, can only be set to jump to links under 3 domains
- A default menu must be created before you can create a personalized menu (the default menu is a menu created using the normal custom menu creation interface). If you delete the default menu, the personalized menu will also be deleted altogether
- The personalized menu interface supports user tags. Please note that when there are more than 1 tags on a user, the last label matches
Updates to the personalized menu will be covered.For example, Official Account has released the default menu, personalized menu 1, personalized menu 2, personalized menu 3.Then when the user enters the Official Account message template, will start from the personalized menu 3 matching, if the personalized menu 3 matching success, then directly return to the personalized menu 3, otherwise continue to try to match personalized menu 2, until the successful match to a menu. Based on the above matching rule, in order to avoid confusion about when a menu takes effect, it was decided not to provide a personalized menu editing API, and developers need to republish the full configuration once they need to update the menu.
# Additional Notes
Media_id for news-type permanent material will no longer be supported in the button. Use article_id instead of matchrule for a total of seven fields. They can all be empty, but not all of them. At least one match message is not empty. Country, province, city constitute area information, will be verified in the order of country, province, city, to conform to the content of the area information table. Regional information is verified from large to small, and small can be filled out, i.e. if the province information is filled out then the national information must be filled in and matched, and the city information can be empty. For example, "Guangzhou, Guangdong Province of China" and "Guangdong Province ofChina" are legal geographical information, while "Guangzhou, China" is not legal because it contains the city information but not the province information.The District Information Sheet is available at Click to download .
# 5. Code examples
# 5.1 Create successfully back
Example Requests
{
"button": [
{
"type": "click",
"name": "今日歌曲",
"key": "V1001_TODAY_MUSIC"
},
{
"name": "菜单",
"sub_button": [
{
"type": "view",
"name": "搜索",
"url": "http://www.soso.com/"
},
{
"type": "miniprogram",
"name": "wxa",
"url": "http://mp.weixin.qq.com",
"appid": "wx286b93c14bbf93aa",
"pagepath": "pages/lunar/index"
},
{
"type": "click",
"name": "赞一下我们",
"key": "V1001_GOOD"
}
]
}
],
"matchrule": {
"tag_id": "2",
"sex": "1",
"country": "中国",
"province": "广东",
"city": "广州",
"client_platform_type": "2",
"language": "zh_CN"
}
}
Return an example
{
"menuid": "208379533"
}
# 5.2 Create failed return
Example Requests
{
"button": [
{
"type": "click",
"name": "今日歌曲",
"key": "V1001_TODAY_MUSIC"
},
{
"name": "菜单",
"sub_button": [
{
"type": "view",
"name": "搜索",
"url": "http://www.soso.com/"
},
{
"type": "miniprogram",
"name": "wxa",
"url": "http://mp.weixin.qq.com",
"appid": "wx286b93c14bbf93aa",
"pagepath": "pages/lunar/index"
},
{
"type": "click",
"name": "赞一下我们",
"key": "V1001_GOOD"
}
]
}
],
"matchrule": {
"tag_id": "2",
"sex": "1",
"country": "中国",
"province": "广东",
"city": "广州",
"client_platform_type": "2",
"language": "zh_CN"
}
}
Return an example
{
"errcode":65320,
"errmsg":"match rule violates privacy"
}
# 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 |
---|---|---|
-1 | system error | The system is busy, so the developer is asked to try again in a few minutes. |
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 |
40007 | invalid media_id | Illegal media file id |
40016 | invalid button size | Number of illegal buttons |
40017 | invalid button type | Unlawful button types |
40018 | invalid button name size | Unlawful button name length |
40019 | invalid button key size | Illegal Button KEY Length |
40020 | invalid button url size | Illegal button URL length |
40023 | invalid sub button size | Number of unlawful submenu buttons |
40024 | invalid sub button type | Unlawful submenu button types |
40027 | invalid sub button url size | Illegal submenu button URL length |
40033 | invalid charset. please check your request if include \uxxxx will create fail! | Invalid request character, cannot contain\ uxxxx format characters |
40054 | invalid sub button url domain | Illegal submenu button url domain name |
40055 | invalid button url domain | Illegal menu button url domain name |
53600 | ArticleID is invalid | Invalid Graphic ID |
65320 | match rule violates privacy | Match rules contain privacy fields |
# 7. Scope of application
Official Account | Service Account |
---|---|
Certification only | Certification only |
- 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;