API call description
This API is designed for internal enterprise system integration scenarios and is used to obtain the access credential required to call DingTalk open capabilities. A typical usage flow is as follows:- Call this API to obtain an access token when the app starts or before the first API call.
- Cache the obtained access token in local storage (such as Redis or in-memory cache) to avoid repeated requests.
- Carry this access token in all subsequent API calls that require authentication.
- Set the cache expiration time slightly shorter than 7,200 seconds (for example, 7,000 seconds) to implement an automatic refresh mechanism and prevent credential expiration caused by time deviations.
- Avoid calling this API frequently within a short period. Otherwise, the rate limit policy may be triggered, affecting service stability.
Request
| Basic information | |
|---|---|
| HTTP URL | https://api.dingtalk.io/v1.0/oauth2/accessToke |
| HTTP Method | POST |
| Supported app type | appType-Internal app |
| Required permissions | permission-qyapi_base-Basic permissions required to call enterprise APIs |
Request body
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
| appKey | String | Yes | dingeqqpkv3xxxxxx | The Client ID of the created internal app. For details on how to obtain it, see the Client ID/Client Secret document. |
| appSecret | String | Yes | GT-lsu-taDAxxxsTsxxxx | The Client Secret of the created internal app. For details on how to obtain it, see the Client ID/Client Secret document. Note Keep the Client Secret secure and prevent it from being leaked. |
Request example
Response
Response body
| Name | Type | Example | Description |
|---|---|---|---|
| accessToken | String | fw8ef8we8f76e6f7s8dxxxx | The generated access token. Note When using the access token, keep the following points in mind: - Cache the access token on your side, and store it separately by app, because the access token of each internal app is independent. - Do not call this API frequently to obtain the credential. Use a caching mechanism to control the call frequency and avoid being rate-limited by the system. |
| expireIn | Long | 7200 | The expiration time of the access token, in seconds. Note The access token is valid for 7,200 seconds (2 hours). Repeated requests within the validity period return the same result and automatically extend the validity. After expiration, a new access token is returned. |
Response body example
Error codes
If an error is returned when calling this API, find the solution based on the error message in the Global error codes document.| HttpCode | Error code | Error message | Description |
|---|---|---|---|
| 400 | invalidClientIdOrSecret | Invalid clientId or clientSecret | Invalid clientId or clientSecret |