# Get stable version interface call credentials

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

  • Obtain the global background interface call credentials, valid for up to 7200s, developers need to properly save;
  • There are two invocation modes: 1. Normal mode,access_tokenRepeated invocation of the interface within the validity period does not updateaccess_token, which is used in most scenarios;2.Force refresh mode, which causes the last access_tokenaccess_tokento be invalidated and returns a newaccess_token
  • The interface is limited to 10, 000 calls per minute and 500 thousand calls per day.
  • Completely isolated from the invocation credentials obtained by getAccessToken .This interface only supports calls in the form ofPOST JSON;
  • If you use the cloud to develop , you can call](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/openapi/openapi.html) through the [cloud without maintenance;
  • Such as using cloud hosting can also be called by WeChat token / open interface to service without maintenance;

# 1. How to call

# HTTPS calls

POST https://api.weixin.qq.com/cgi-bin/stable_token

# Cloud Calls

  • This interface does not support cloud calls

# Third party invocation

  • Third Party Platform calls are not supported by this interface.

# 2. Request parameters

# Query parametersQuery String parameters

nothing

# Request BodyRequest Payload

Parameter NametypeRequired to fill inIntroductions
grant_typestringyesFill in client_credential
appidstringyesThe account's unique credentials, that is, AppID, click here to see How to get Appid
secretstringyesUnique credential key, AppSecret, click here to see How to get AppSecret
force_refreshbooleannoFalse is used by default. 1.When force_refresh = false, it is called in normal mode, access_token repeatedly calling the interface within the validity period does not update access_token;2.Forced refresh mode when force_refresh = true, invalidates the last access_token acquired and returns a new access_token

# 3. Return Parameters

# Response Payload

Parameter NametypeIntroductions
access_tokenstringCredentials obtained
expires_innumberCredential validity time, in units: seconds. The current value is within 7,200 seconds.

# 4. Note

  1. The frequency of the interface calls is limited to 10,000 times per minute and 50w times per day.It is completely isolated from the credentials of that get the interface call credentials .
  2. This interface only supports calls in the form of POST JSON;
  3. "access_token storage space is reserved for at least 512 characters,"
  4. "The mandatory refresh mode is limited to 20 times per day at intervals of 30 seconds,"
  5. "In normal mode, the platform is updated 5 minutes earlier access_token"

# 5. Code examples

# 5.1 Does not force refresh to get the token (force_refresh is not passed, default is false)

Example Requests

POST https://api.weixin.qq.com/cgi-bin/stable_token
{
    "grant_type": "client_credential",
    "appid": "APPID",
    "secret": "APPSECRET"
}

Return an example

{
    "access_token":"ACCESS_TOKEN",
    "expires_in":7200
}

# 5.2 Do not force refresh to get the token (set force_refresh to false):

Example Requests

{
    "grant_type": "client_credential",
    "appid": "APPID",
    "secret": "APPSECRET",
    "force_refresh": false
} 

Return an example

{
    "access_token":"ACCESS_TOKEN",
    "expires_in":345 // 如果仍然有效,会返回上次的 token,并给出所剩有效时间
} 

# 5.3 Mandatory refresh mode, use with caution, continuous use requires at least 30 s interval

Example Requests

POST https://api.weixin.qq.com/cgi-bin/stable_token
{
    "grant_type": "client_credential",
    "appid": "APPID",
    "secret": "APPSECRET",
    "force_refresh": true
} 

Return an example

{
    "access_token":"ACCESS_TOKEN",
    "expires_in":7200
} 

# 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.
0okok
40002invalid grant_typeTypes of Unlawful Credentials
40013invalid appidInvalid AppID, please check the correctness of the AppID, avoid abnormal characters, pay attention to the case
40125invalid appsecretInvalid appsecret, please check the correctness of appsecret
40164invalid ip  not in whitelistAdd ip to the ip whitelisting list
41002appid missingMissing AppID parameter
41004appsecret missingMissing secret parameter
43002require POST methodNeed POST Request
45009reach max api daily quota limitCalls exceed the day-level frequency limit. The clear_quota interface can be called to restore the call quota.
45011api minute-quota reach limit  mustslower  retry next minuteAPI calls are too frequent, please try again later
89503This call requires administrator confirmation. Please be patient.undefined
89506This IP call request has been rejected by Official Account administrator. Please try again after 24 hours. It is recommended to confirm with administrator before callingundefined
89507This IP call request has been rejected by Official Account administrator. Please try again after 1 hour. It is recommended to confirm with administrator before calling.undefined

# 7. Scope of application

How this interface can be invoked under different account types:
Weixin Mini Program Official Account Service Account MiniGame Weixin Store Alliance Shipping Agency Delivery Assistant Mobile App Website App Weixin Channels Assistant Multi-platform App
  • ✔: The account can call this interface
  • Other account types that are not expressly stated may not be called on this interface without special instructions;