This API should be called on the server side and cannot be called directly on the client side (Mini Program, web page, APP, etc.). For details, please refer to API Call Guide.
API English Name: getStableAccessToken
This interface is used to retrieve a globally unique backend API call credential (Access Token). The token is valid for 7,200 seconds. However, this interface is separate from getAccessToken and more stable. It is recommended to use this interface instead. Developers should store it properly. For usage guidelines, please refer to this document.
There are two call modes:
- Normal mode: Repeated calls to this interface within the validity period of the
access_tokenwill not update theaccess_token. This mode is used in most scenarios. - Forced refresh mode: This will invalidate the previously obtained
access_tokenand return a new one.
- If using Cloud Development, you can use Cloud Calls to manage
access_tokencalls without maintenance. - If using Cloud Hosting, you can also use WeChat Token/Open API Service to manage
access_tokencalls without maintenance.
1. Call Method
HTTPS Call
POST https://api.weixin.qq.com/cgi-bin/stable_token
Cloud Call
- This API does not support cloud call.
Third-party Call
- This API does not support third-party platform calls.
2. Request Parameters
Query Parameters Query String Parameters
None
Request Body Request Payload
| Parameter | Type | Required | Description |
|---|---|---|---|
| grant_type | string | Yes | Enter client_credential |
| appid | string | Yes | The unique credential for the account, namely AppID. Click here to view how to obtain an AppID. |
| secret | string | Yes | The unique credential key, namely AppSecret. Click here to view how to obtain an AppSecret. |
| force_refresh | boolean | No | The default value is false. 1. When force_refresh = false, it is in normal call mode, and repeated calls to this interface within the validity period of the `access_token` will not update the `access_token`. 2. When force_refresh = true, it is in forced refresh mode, which will invalidate the previously obtained `access_token` and return a new one. |
3. Response Parameters
Response Body Response Payload
| Parameter | Type | Description |
|---|---|---|
| access_token | string | The obtained credentials |
| expires_in | number | Credential validity period, in seconds. Currently, it is within 7,200 seconds. |
4. Notes
- The call credentials obtained through getAccessToken are completely separate and do not affect each other.
- This interface only supports
POSTrequests. - The call frequency limit for this interface is 10,000 times per minute, with a daily limit of 500,000 times.
- The
access_tokenmust have at least 512 characters in storage space. - The forced refresh mode is limited to 20 times per day, with a 30-second interval required.
- In normal mode, the platform will update the
access_token5 minutes in advance.
5. Code Example
5.1 Obtain Token without Forced Refresh (Do not pass force_refresh; the default value is false)
Request Example
POST https://api.weixin.qq.com/cgi-bin/stable_token
{
"grant_type": "client_credential",
"appid": "APPID",
"secret": "APPSECRET"
}
Response Example
{
"access_token":"ACCESS_TOKEN",
"expires_in":7200
}
5.2 Obtain Token without Forced Refresh (Set force_refresh to false):
Request Example
{
"grant_type": "client_credential",
"appid": "APPID",
"secret": "APPSECRET",
"force_refresh": false
}
Response Example
{
"access_token":"ACCESS_TOKEN",
"expires_in":345 // If it is still valid, the previous token will be returned along with the remaining validity time
}
5.3 Use the forced refresh mode with caution. A minimum interval of 30 seconds is required for consecutive uses.
Request Example
POST https://api.weixin.qq.com/cgi-bin/stable_token
{
"grant_type": "client_credential",
"appid": "APPID",
"secret": "APPSECRET",
"force_refresh": true
}
Response Example
{
"access_token":"ACCESS_TOKEN",
"expires_in":7200
}
6. Error Codes
The following is the error code list of this API, other error codes can refer to Common Error Codes; When encountering errors in calling the API, you can use the official API Diagnostic Tool to assist in locating and analyzing problems.
| Error Code | Error Description | Solution |
|---|---|---|
| -1 | system error | The system is busy. Please try again later. |
| 0 | ok | ok |
| 40002 | invalid grant_type | Invalid credential type |
| 40013 | invalid appid | Invalid AppID. Please check the correctness of the AppID, avoiding special characters and paying attention to case sensitivity. |
| 40125 | invalid appsecret | Invalid appsecret. Please check the correctness of the appsecret. |
| 40164 | invalid ip not in whitelist | Add the IP address to the IP whitelist list. |
| 41002 | appid missing | Missing appid parameter |
| 41004 | appsecret missing | Missing secret parameter |
| 43002 | require POST method | A POST request is required. |
| 45009 | reach max api daily quota limit | The call exceeds the daily frequency limit. You can call the clear_quota interface to restore the call quota. |
| 45011 | api minute-quota reach limit mustslower retry next minute | The API is called too frequently. Please try again later. |
| 89503 | This call requires administrator confirmation. Please wait patiently. | |
| 89506 | The call request from this IP has been rejected by the public account administrator. Please try again after 24 hours. It is recommended to communicate with the administrator before making the call. | |
| 89507 | The call request from this IP has been rejected by the public account administrator. Please try again after 1 hour. It is recommended to communicate with the administrator before making the call. |
7. Applicable Scope
| Mini Program | Official Account | Service Account | Mini Game | WeChat Shop | Alliance Agency | Influencer | Shop Supplier | Mobile App | Website App | Channels Window | Multi-platform App |
|---|---|---|---|---|---|---|---|---|---|---|---|
| ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
- ✔:This account type can call this API。
- Other account types not explicitly declared cannot call this API unless otherwise specified.