> ## 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 | 是    | 1\*\*\*\*\*\*\*543 | 用户的手机号。 |

### 请求示例

```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=2015ca04-c84e-4855-9e52-330b98eb35f5' \
-d 'mobile=13800138000'
```

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("1*******543");
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");
$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 = "13800138000";
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。 |

### 响应体示例

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errcode":"0",
  "result":{
    "userid":"xiaoding"
  },
  "errmsg":"ok"
}
```

### 错误码

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

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