> ## 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.

# 根据手机号查询企业账号用户

> 调用本接口可根据手机号查询企业账号用户的 userId,员工离职后无法通过手机号获取其 userId。

调用本接口根据手机号获取企业账号用户的userId，如果员工离职，无法通过手机号获取用户的userId。

## 请求

| **基本信息**    |                                                                                                          |
| ----------- | -------------------------------------------------------------------------------------------------------- |
| HTTP URL    | [https://api.dingtalk.io/topapi/v2/user/getbymobile](https://api.dingtalk.io/topapi/v2/user/getbymobile) |
| HTTP Method | POST                                                                                                     |
| 支持的应用类型     | appType-企业内部应用                                                                                           |
| 权限要求        | permission-qyapi\_get\_member\_by\_mobile-根据手机号获取成员基本信息权限                                                |

### 查询参数

| 名称            | 类型     | 是否必填 | 示例值      | 描述                                                                                   |
| ------------- | ------ | ---- | -------- | ------------------------------------------------------------------------------------ |
| access\_token | String | 是    | be3Fxxxx | 调用该接口的应用凭证，通过[获取企业内部应用的access\_token](/zh/open/development/obtain-orgapp-token)接口获取。 |

### 请求体

| 名称                                  | 类型      | 是否必填 | 示例值         | 描述                                                                                              |
| ----------------------------------- | ------- | ---- | ----------- | ----------------------------------------------------------------------------------------------- |
| mobile                              | String  | 是    | 185xxxxx676 | 用户的手机号。                                                                                         |
| support\_exclusive\_account\_search | Boolean | 是    | true        | 是否支持通过手机号搜索企业账号。   - **true**：支持。 - **fasle**：不支持。   **说明**     - 仅适用于企业账号。 - 仅支持搜索当前企业创建的企业账号。 |

### 请求示例

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.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

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
DingTalkClient client = new DefaultDingTalkClient("https://api.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

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

req=dingtalk.api.OapiV2UserGetbymobileRequest("https://api.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

```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 OapiV2UserGetbymobileRequest;
$req->setMobile("13800138000");
$req->setSupportExclusiveAccountSearch("true");
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/v2/user/getbymobile");
```

C#

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.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\_id                      | String    | 5w82ciuur781        | 请求ID。                                      |
| errcode                          | Number    | 0                   | 返回码。                                       |
| errmsg                           | String    | ok                  | 返回码描述。                                     |
| result                           | Object    |                     | 返回结果。                                      |
| userid                           | String    | zhangsan            | 员工的userId。                                 |
| exclusive\_account\_userid\_list | String\[] | \["zxxxx","lixxxi"] | 企业账号员工的userId列表。  **说明**  只返回由当前组织创建的企业账号。 |

### 响应体示例

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errcode":"0",
  "result":{
    "exclusive_account_userid_list":"[\"zxxxx\",\"lixxxi\"]",
    "userid":"zhangsan"
  },
  "errmsg":"ok"
}
```

### 错误码

若调用该接口报错，可根据错误信息在[全局错误码](/zh/open/development/server-api-error-codes-1)文档中查找解决方案。

| 错误码（errcode） | 错误码描述（errmsg） | 解决方案              |
| ------------ | ------------- | ----------------- |
| 400002       | 无效的参数         | 请确认参数是否按照上述文档要求填写 |
| 40104        | 企业中无效的手机号     | 请检查手机号是否正确        |
| 60121        | 未找到该用户        | 请确认信息填写是否正确       |
| -1           | 系统繁忙          | 请稍后再试             |
