Skip to main content

Request

Basic information
HTTP URLhttps://oapi.dingtalk.io/topapi/v2/user/getuserinfo
HTTP MethodPOST
Supported app typesappType-Internal appappType-Third-party enterprise app
Required permissionspermission-qyapi_base-Basic permissions required to call enterprise APIs

Query parameters

NameTypeRequiredExampleDescription
access_tokenStringYes6ed1bxxxThe 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. - For a third-party enterprise app, obtain it through the API to get the access_token of a third-party enterprise.

Request body

NameTypeRequiredExampleDescription
codeStringYesbab02f63c1e030fbbxxxxThe 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 -X POST "https://oapi.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
DingTalkClient client = new DefaultDingTalkClient("https://oapi.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
# -*- coding: utf-8 -*-
import dingtalk.api

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

req.code="123456"
try:
  resp= req.getResponse(access_token)
  print(resp)
except Exception,e:
  print(e)
PHP
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://oapi.dingtalk.io/topapi/v2/user/getuserinfo");
Node.js
let { Config, OapiV2UserGetuserinfoParams, OapiV2UserGetuserinfoRequest } = require('./client.js');
let Client = require('./client.js').default
async function test() {
  const config = new Config()
  config.serverUrl = 'https://oapi.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#
IDingTalkClient client = new DefaultDingTalkClient("https://oapi.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

NameTypeExampleDescription
request_idStringe8krly4vyilnThe request ID.
errcodeNumber0The return code**.**
errmsgStringokThe text description of the return code.
resultUserGetByCodeResponseThe returned result.
useridStringuser456The user ID of the user.
device_idString12drtfxxxxxThe device ID.
sysBooleantrueIndicates whether the user is an admin. - true: Yes - false: No
sys_levelNumber1The admin level. - 1: Super Admin - 2: Sub Admin - 100: Boss - 0: Other (such as a regular employee)
associated_unionidStringN2o5U3axxxxThe unionId associated with the user.
unionidStringgliiW002zUxxxxThe unionId of the user.
nameStringZhang xxThe name of the user.

Response body example

{
  "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 document based on the error message.