> ## 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 basic user information

> Call this API to get basic user information via the SSO authorization code, used for identity recognition in DingTalk SSO scenarios.

Call this API to get basic user information through the silent login authorization code.

## Request

| **Basic information** |                                                                                                              |
| --------------------- | ------------------------------------------------------------------------------------------------------------ |
| HTTP URL              | [https://api.dingtalk.io/v1.0/sns/getuserinfo\_bycode](https://api.dingtalk.io/v1.0/sns/getuserinfo_bycode)  |
| HTTP Method           | POST                                                                                                         |
| Supported app types   | appType-Internal appappType-Third-party enterprise app                                                       |
| Permissions           | permission-open\_app\_api\_base-Basic permission to obtain the user access credential for DingTalk open APIs |

### Query parameters

| Name      | **Type** | Required | Description                                                                                                                                            |
| --------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| accessKey | String   | Yes      | The AppId of the app.                                                                                                                                  |
| timestamp | String   | Yes      | The current timestamp, in milliseconds.                                                                                                                |
| signature | String   | Yes      | The signature value calculated using the HmacSHA256 algorithm, with timestamp+"\n"+AppSecret as the signature string and AppSecret as the signing key. |

### Request body

| Name            | Type   | Required | Description                                                                                                                                                                         |
| --------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| tmp\_auth\_code | String | Yes      | The silent login authorization code granted by the user to the DingTalk open app. Obtain it by calling the JSAPI `dd.getAuthCode`. See silent login authorization code for details. |

### Request example

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.dingtalk.io/v1.0/sns/getuserinfo_bycode" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'tmp_auth_code=abcdef'
```

Java

```java theme={"theme":{"light":"github-light","dark":"github-dark"}}
DefaultDingTalkClient  client = new DefaultDingTalkClient("https://api.dingtalk.io/v1.0/sns/getuserinfo_bycode");
// If this class does not exist in your SDK, download the latest SDK
OapiSnsGetuserinfoBycodeRequest req = new OapiSnsGetuserinfoBycodeRequest();
req.setTmpAuthCode("4a2c5695b78738d495f47b5fee9160cd");
OapiSnsGetuserinfoBycodeResponse response = client.execute(req,"yourAppId","yourAppSecret");
```

Python

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import dingtalk.api

req = dingtalk.api.OapiSnsGetuserinfoBycodeRequest("https://api.dingtalk.io/v1.0/sns/getuserinfo_bycode")
req.tmp_auth_code = "abcdef"
try:
  resp = req.getResponse("yourAppId", "yourAppSecret")
  print(resp)
except Exception as 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 OapiSnsGetuserinfoBycodeRequest;
$req->setTmpAuthCode("abcdef");
$resp = $c->execute($req,"yourAppId","yourAppSecret", "https://api.dingtalk.io/v1.0/sns/getuserinfo_bycode");
```

C#

```csharp theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/v1.0/sns/getuserinfo_bycode");
OapiSnsGetuserinfoBycodeRequest req = new OapiSnsGetuserinfoBycodeRequest();
req.TmpAuthCode = "abcdef";
OapiSnsGetuserinfoBycodeResponse rsp = client.Execute(req, "yourAppId", "yourAppSecret");
Console.WriteLine(rsp.Body);
```

## Response

### Response body example

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errcode": 0,
  "errmsg": "ok",
  "user_info": {
    "nick": "John",
    "unionid": "Wzh9KbyaCZxxx",
    "openid": "EtiiaAu3Yf9Ruxxx",
    "main_org_auth_high_level": true
  }
}
```

### Error codes

If an error occurs when calling this API, refer to the [global error codes](/open/development/server-api-error-codes-1) document to find a solution based on the error message.

| **Error code** | **Description**                                                                                                                                                   |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 853002         | The timestamp parameter is invalid. The value differs from the current time on the DingTalk server by more than 1 minute.                                         |
| 853001         | The timestamp parameter format is incorrect. It must be the current time in milliseconds.                                                                         |
| 853003         | The accessKey parameter is invalid. It must be an appId that exists on the DingTalk Open Platform.                                                                |
| 853004         | The signature parameter is incorrect and does not match the signature calculated by the DingTalk server. Note that this parameter must be urlEncoded when passed. |
