> ## 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 を検索します

本 API を呼び出すことで、電話番号から在職中の社員の 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 | 本 API を呼び出すアプリ認証情報。[社内アプリの access\_token を取得する](/ja/open/development/obtain-orgapp-token) API から取得します。 |

### リクエストボディ

| 名前     | タイプ    | 必須 | 例                  | 説明         |
| ------ | ------ | -- | ------------------ | ---------- |
| 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"
}
```

### エラーコード

本 API の呼び出しでエラーが発生した場合は、エラーメッセージをもとに[グローバルエラーコード](/ja/open/development/server-api-error-codes-1)ドキュメントから解決方法を検索してください。

| エラーコード（errcode） | エラーコードの説明（errmsg） | 解決方法                                  |
| --------------- | ----------------- | ------------------------------------- |
| 400002          | 無効なパラメータ          | 上記ドキュメントの要件に従ってパラメータが入力されているか確認してください |
| 40104           | 企業内で無効な電話番号       | 電話番号が正しいか確認してください                     |
| 60121           | ユーザーが見つかりません      | 入力情報が正しいか確認してください                     |
| -1              | システムビジー           | 後でもう一度お試しください                         |
