Skip to main content
Call this API to get the user ID of an active employee by their mobile number. If the employee has left the organization, the user ID cannot be retrieved by mobile number.

Request

Basic information
HTTP URLhttps://oapi.dingtalk.io/topapi/v2/user/getbymobile
HTTP MethodPOST
Supported app typeappType-Internal app
Required permissionspermission-qyapi_get_member_by_mobile-Permission to get basic user information by mobile number

Query parameters

NameTypeRequiredExampleDescription
access_tokenStringYesbe3FxxxxThe app credential for calling this API. Obtain it through the API for getting the access_token of an internal app.

Request body

NameTypeRequiredExampleDescription
mobileStringYes1*******543The mobile number of the user.

Request example

curl -X POST "https://oapi.dingtalk.io/topapi/v2/user/getbymobile" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=2015ca04-c84e-4855-9e52-330b98eb35f5' \
-d 'mobile=13800138000'
Java
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/topapi/v2/user/getbymobile");
OapiV2UserGetbymobileRequest req = new OapiV2UserGetbymobileRequest();
req.setMobile("1*******543");
OapiV2UserGetbymobileResponse rsp = client.execute(req, acces_token);
System.out.println(rsp.getBody());
Python
import dingtalk.api

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

req.mobile="13800138000"
req.support_exclusive_account_search=true
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 OapiV2UserGetbymobileRequest;
$req->setMobile("13800138000");
$resp = $c->execute($req, $access_token, "https://oapi.dingtalk.io/topapi/v2/user/getbymobile");
C#
IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/topapi/v2/user/getbymobile");
OapiV2UserGetbymobileRequest req = new OapiV2UserGetbymobileRequest();
req.Mobile = "13800138000";
OapiV2UserGetbymobileResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);

Response

Response body

NameTypeExampleDescription
request_idString5w82ciuur781The request ID.
errcodeNumber0The return code.
errmsgStringokThe description of the return code.
resultObjectThe returned result.
useridStringzhangsanThe user ID of the employee.

Response example

{
  "errcode":"0",
  "result":{
    "userid":"xiaoding"
  },
  "errmsg":"ok"
}

Error codes

If an error occurs when calling this API, refer to the Global error codes document for solutions based on the error message.
Error code (errcode)Error message (errmsg)Solution
400002Invalid parameterMake sure the parameters are filled in as required in the document above.
40104Invalid mobile number in the organizationCheck whether the mobile number is correct.
60121User not foundConfirm that the information is filled in correctly.
-1System busyTry again later.