跳转到主要内容
调用本接口根据手机号获取企业账号用户的userId,如果员工离职,无法通过手机号获取用户的userId。

请求

基本信息
HTTP URLhttps://oapi.dingtalk.io/topapi/v2/user/getbymobile
HTTP MethodPOST
支持的应用类型appType-企业内部应用
权限要求permission-qyapi_get_member_by_mobile-根据手机号获取成员基本信息权限

查询参数

名称类型是否必填示例值描述
access_tokenStringbe3Fxxxx调用该接口的应用凭证,通过获取企业内部应用的access_token接口获取。

请求体

名称类型是否必填示例值描述
mobileString185xxxxx676用户的手机号。
support_exclusive_account_searchBooleantrue是否支持通过手机号搜索企业账号。 - true:支持。 - fasle:不支持。 说明 - 仅适用于企业账号。 - 仅支持搜索当前企业创建的企业账号。

请求示例

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=a16xxxxa2efbee' \
-d 'mobile=1851xxxx676' \
-d 'support_exclusive_account_search=true'
Java
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/topapi/v2/user/getbymobile");
OapiV2UserGetbymobileRequest req = new OapiV2UserGetbymobileRequest();
req.setMobile("185xxxx");
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");
$req->setSupportExclusiveAccountSearch("true");
$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 = "1851xxxx76";
req.SupportExclusiveAccountSearch = true;
OapiV2UserGetbymobileResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);

响应

响应体

名称类型示例值描述
request_idString5w82ciuur781请求ID。
errcodeNumber0返回码。
errmsgStringok返回码描述。
resultObject返回结果。
useridStringzhangsan员工的userId。
exclusive_account_userid_listString[][“zxxxx”,“lixxxi”]企业账号员工的userId列表。 说明 只返回由当前组织创建的企业账号。

响应体示例

{
  "errcode":"0",
  "result":{
    "exclusive_account_userid_list":"[\"zxxxx\",\"lixxxi\"]",
    "userid":"zhangsan"
  },
  "errmsg":"ok"
}

错误码

若调用该接口报错,可根据错误信息在全局错误码文档中查找解决方案。
错误码(errcode)错误码描述(errmsg)解决方案
400002无效的参数请确认参数是否按照上述文档要求填写
40104企业中无效的手机号请检查手机号是否正确
60121未找到该用户请确认信息填写是否正确
-1系统繁忙请稍后再试