# Create personalized menus

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: 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:

  1. When created, any matching condition that contains private messaging will be rejected and the error code 65320 will be returned;
  2. Those that have been created automatically expire if they contain private messages, and those that do not are matched normally;
  3. Developers can still get the menus that fans see through the test interface normally.
  4. 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 NametypeRequired to fill inExampleIntroductions
access_tokenstringyesACCESS_TOKENInterface invocation credentials, using access_token , authorizer_access_token

# Request BodyRequest Payload

Parameter NametypeRequired to fill inIntroductions
buttonobjarrayyesLevel 1 menu array (1 to 3 items)
matchruleobjectyesMenu Match Rules (at least one non-empty field)

# Body.button(Array)Object Payload

Level 1 menu array (1 to 3 items)

Parameter NametypeRequired to fill inExampleIntroductionsto enumerate
typestringnoclickResponse 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
namestringyesSongs of the dayMenu title, no more than 16 bytes, submenu no more than 60 bytes-
keystringno-The menu KEY value, used for message interface push, does not exceed 128 bytes. Click, etc. Click types must be.-
urlstringno-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_idstringno-The valid media_id returned by calling the new permanent material interface. The media_id type and the view_limited type must-
appidstringno-Weixin Mini Program of AppID (only Official Account can be configured), the miniprogram type must-
pagepathstringno-The page path of Weixin Mini Program, the miniprogram type must-
article_idstringno-The legal article_id, article_id type, and article_view_limited type obtained after publication must be-
sub_buttonobjarrayno-Array of secondary menu structures-

# Body.matchruleObject Payload

Menu Match Rules (at least one non-empty field)

Parameter NametypeRequired to fill inExampleIntroductions
tag_idstringno-The id of the user tag, which can be obtained through the user tag management interface
client_platform_typestringno1Customer 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 NametypeRequired to fill inExampleIntroductions
typestringyesclickThe response action type of the menu (type of the same level menu)
namestringyesSongs of the dayMenu title, no more than 16 bytes, submenu no more than 60 bytes
keystringno-The menu KEY value, used for message interface push, does not exceed 128 bytes. Click, etc. Click types must be.
urlstringno-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_idstringno-The valid media_id returned by calling the new permanent material interface. The media_id type and the view_limited type must
appidstringno-Weixin Mini Program of AppID (only Official Account can be configured), the miniprogram type must
pagepathstringno-The page path of Weixin Mini Program, the miniprogram type must
article_idstringno-The legal article_id, article_id type, and article_view_limited type obtained after publication must be

# 3. Return Parameters

# Response Payload

Parameter NametypeExampleIntroductions
menuidstring208379533Menu ID
errcodenumber-Error code
errmsgstring-Error Description

# 4. Note

  1. 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
  2. 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.
  3. 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
  4. For security reasons, a Official Account for all personalized menus, can only be set to jump to links under 3 domains
  5. 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
  6. 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 codeError DescriptionSolutions
-1system errorThe system is busy, so the developer is asked to try again in a few minutes.
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
40007invalid media_idIllegal media file id
40016invalid button sizeNumber of illegal buttons
40017invalid button typeUnlawful button types
40018invalid button name sizeUnlawful button name length
40019invalid button key sizeIllegal Button KEY Length
40020invalid button url sizeIllegal button URL length
40023invalid sub button sizeNumber of unlawful submenu buttons
40024invalid sub button typeUnlawful submenu button types
40027invalid sub button url sizeIllegal submenu button URL length
40033invalid charset. please check your request  if include \uxxxx will create fail!Invalid request character, cannot contain\ uxxxx format characters
40054invalid sub button url domainIllegal submenu button url domain name
40055invalid button url domainIllegal menu button url domain name
53600ArticleID is invalidInvalid Graphic ID
65320match rule violates privacyMatch rules contain privacy fields

# 7. Scope of application

How this interface can be invoked under different account types:
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;