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

# Get a user by mobile number

> Call this API to query the userId of an active employee by mobile number. The userId of resigned employees cannot be retrieved by mobile number.

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 URL              | [https://api.dingtalk.io/topapi/v2/user/getbymobile](https://api.dingtalk.io/topapi/v2/user/getbymobile) |
| HTTP Method           | POST                                                                                                     |
| Supported app type    | appType-Internal app                                                                                     |
| Required permissions  | permission-qyapi\_get\_member\_by\_mobile-Permission to get basic user information by mobile number      |

### Query parameters

| Name          | Type   | Required | Example  | Description                                                                                                                                                   |
| ------------- | ------ | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| access\_token | String | Yes      | be3Fxxxx | The app credential for calling this API. Obtain it through the API for getting the [access\_token of an internal app](/open/development/obtain-orgapp-token). |

### Request body

| Name   | Type   | Required | Example            | Description                    |
| ------ | ------ | -------- | ------------------ | ------------------------------ |
| mobile | String | Yes      | 1\*\*\*\*\*\*\*543 | The mobile number of the user. |

### Request example

```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);
```

## Response

### Response body

| Name        | Type   | Example      | Description                         |
| ----------- | ------ | ------------ | ----------------------------------- |
| request\_id | String | 5w82ciuur781 | The request ID.                     |
| errcode     | Number | 0            | The return code.                    |
| errmsg      | String | ok           | The description of the return code. |
| result      | Object |              | The returned result.                |
| userid      | String | zhangsan     | The user ID of the employee.        |

### Response example

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

### Error codes

If an error occurs when calling this API, refer to the [Global error codes](/open/development/server-api-error-codes-1) document for solutions based on the error message.

| Error code (errcode) | Error message (errmsg)                    | Solution                                                                  |
| -------------------- | ----------------------------------------- | ------------------------------------------------------------------------- |
| 400002               | Invalid parameter                         | Make sure the parameters are filled in as required in the document above. |
| 40104                | Invalid mobile number in the organization | Check whether the mobile number is correct.                               |
| 60121                | User not found                            | Confirm that the information is filled in correctly.                      |
| -1                   | System busy                               | Try again later.                                                          |
