Get the user ID by unionId
API call description
A unionId is a unique identifier assigned to an employee within the scope of the current developer Enterprise Account, generated by the system:- The unionId of the same employee differs across different developer Enterprise Accounts.
- Within the same developer Enterprise Account, the unionId is unique and immutable. For example, multiple apps developed by the same service provider, or multiple app accounts in scenarios such as Scan QR Code sign-in, all share the same unionId.
Request
| Basic information | |
|---|---|
| HTTP URL | https://oapi.dingtalk.io/topapi/user/getbyunionid |
| HTTP Method | POST |
| Supported app types | appType-Internal app, appType-Third-party enterprise app |
| Required permissions | permission-qyapi_get_member-Read permission for user information |
Query parameter
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
| access_token | String | Yes | be3Fxxxx | The app credential used to call this API. Note If the unionId was obtained through silent login, you cannot use the token obtained from silent login to call this API. You must obtain a new token using the APIs below. - For an internal app, obtain the access_token through the API for getting the access_token of an internal app. - For a third-party enterprise app, obtain the access_token through the API for getting the access_token of a third-party enterprise. |
Request body
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
| unionid | String | Yes | z21HjQliSzpw0Yxxxx | The unique identifier of an employee within the scope of the current developer Enterprise Account. It is generated by the system and remains unchanged. You can get the unionId by calling Get the user ID of a user by using the silent login code. |
Request example
Response
Response body
| Name | Type | Example | Description |
|---|---|---|---|
| request_id | String | zcqi5450rpit | The request ID. |
| errcode | Number | 0 | The return code. |
| errmsg | String | ok | The description of the return code. |
| result | UserGetByUnionIdResponse | The returned result. | |
| contact_type | Number | 0 | The contact type: - 0: Internal employee - 1: External contact |
| userid | String | zhangsan | The user ID of the user. |
Response body example
Error codes
If an error occurs when calling this API, look up the solution by error message in the Global error codes document.| Error code (errcode) | Error message (errmsg) | Solution |
|---|---|---|
| 60121 | The corresponding employee is not found. | Check whether the unionId is correct. |
| 400002 | Invalid parameter. | Check whether the unionId is correct. |
| -1 | The system is busy. | Try again later. |