> ## Documentation Index
> Fetch the complete documentation index at: https://help.dingtalk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Get user information by silent login code

> Call this API to get user information by silent login code, suitable for identifying the current user in silent-login scenarios within DingTalk client apps.

## Request

| **Basic information** |                                                                                                          |
| --------------------- | -------------------------------------------------------------------------------------------------------- |
| HTTP URL              | [https://api.dingtalk.io/topapi/v2/user/getuserinfo](https://api.dingtalk.io/topapi/v2/user/getuserinfo) |
| HTTP Method           | POST                                                                                                     |
| Supported app types   | appType-Internal appappType-Third-party enterprise app                                                   |
| Required permissions  | permission-qyapi\_base-Basic permissions required to call enterprise APIs                                |

### Query parameters

| Name          | Type   | Required | Example  | Description                                                                                                                                                                                                                                                                                            |
| ------------- | ------ | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| access\_token | String | Yes      | 6ed1bxxx | The app credential used to call this API.   - For an internal app, obtain it through the API to get the [access\_token of an internal app](/open/development/obtain-orgapp-token). - For a third-party enterprise app, obtain it through the API to get the access\_token of a third-party enterprise. |

### Request body

| Name | Type   | Required | Example               | Description                                                                                                                                                                                                                                                    |
| ---- | ------ | -------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| code | String | Yes      | bab02f63c1e030fbbxxxx | The silent login authorization code. For how to obtain it, see:   - Silent login authorization code for a mini program - Silent login authorization code for a micro app   **Note**  This authorization code is valid for 5 minutes and can be used only once. |

### Request example

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.dingtalk.io/topapi/v2/user/getuserinfo" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=417124xxxx2a3c270d5' \
-d 'code=123456'
```

Java

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
DingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/v2/user/getuserinfo");
OapiV2UserGetuserinfoRequest req = new OapiV2UserGetuserinfoRequest();
req.setCode("bab02f63c1e030fbbxxxx");
OapiV2UserGetuserinfoResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
```

Python

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
# -*- coding: utf-8 -*-
import dingtalk.api

req=dingtalk.api.OapiV2UserGetuserinfoRequest("https://api.dingtalk.io/topapi/v2/user/getuserinfo")

req.code="123456"
try:
  resp= req.getResponse(access_token)
  print(resp)
except Exception,e:
  print(e)
```

PHP

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');

$c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
$req = new OapiV2UserGetuserinfoRequest;
$req->setCode("123456");
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/v2/user/getuserinfo");
```

Node.js

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"}}
let { Config, OapiV2UserGetuserinfoParams, OapiV2UserGetuserinfoRequest } = require('./client.js');
let Client = require('./client.js').default
async function test() {
  const config = new Config()
  config.serverUrl = 'https://api.dingtalk.io/topapi/v2/user/getuserinfo'
  config.session = 'access_token'
  const params = new OapiV2UserGetuserinfoParams();
  params.code = 'bab02f63c1e030fbbxxxx'

  const request = new OapiV2UserGetuserinfoRequest()
  request.params = params
  const client = new Client(config)
  try {
    const res = await client.oapiV2UserGetuserinfo(request)
    console.log(res.body)
  } catch (err) {
    console.log(err)
  }
}
test()
```

C#

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/v2/user/getuserinfo");
OapiV2UserGetuserinfoRequest req = new OapiV2UserGetuserinfoRequest();
req.Code = "123456";
OapiV2UserGetuserinfoResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);
```

## Response

### Response body

| Name                | Type                  | Example        | Description                                                                                                            |
| ------------------- | --------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------- |
| request\_id         | String                | e8krly4vyiln   | The request ID.                                                                                                        |
| errcode             | Number                | 0              | The return code\*\*.\*\*                                                                                               |
| errmsg              | String                | ok             | The text description of the return code.                                                                               |
| result              | UserGetByCodeResponse |                | The returned result.                                                                                                   |
| userid              | String                | user456        | The user ID of the user.                                                                                               |
| device\_id          | String                | 12drtfxxxxx    | The device ID.                                                                                                         |
| sys                 | Boolean               | true           | Indicates whether the user is an admin.   - **true**: Yes - **false**: No                                              |
| sys\_level          | Number                | 1              | The admin level.   - **1**: Super Admin - **2**: Sub Admin - **100**: Boss - **0**: Other (such as a regular employee) |
| associated\_unionid | String                | N2o5U3axxxx    | The unionId associated with the user.                                                                                  |
| unionid             | String                | gliiW002zUxxxx | The unionId of the user.                                                                                               |
| name                | String                | Zhang xx       | The name of the user.                                                                                                  |

### Response body example

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errcode": 0, 
  "result": {
    "associated_unionid": "N2o5U3axxxx", 
    "unionid": "gliiW0piiii02zBUjUxxxx", 
    "device_id": "12drtfxxxxx", 
    "sys_level": 1, 
    "name": "John Doe", 
    "sys": true, 
    "userid": "userid123"
  }, 
  "errmsg": "ok"
}
```

### Error codes

If an error is returned when you call this API, find the solution in the [Global error codes](/open/development/server-api-error-codes-1) document based on the error message.
