[comment]: # ({33b90954-f9e8f670})
# 创建

[comment]: # ({/33b90954-f9e8f670})

[comment]: # ({618f9eb8-b5ff62ed})
### 描述

`object userdirectory.create(object/array userDirectory)`

此方法用于创建新的用户目录。

::: noteclassic
此方法仅适用于*Super admin(超级管理员)*类型的用户。
:::

[comment]: # ({/618f9eb8-b5ff62ed})

[comment]: # ({9d471e91-d99c84a0})

### 参数

`(object/array)` 要创建的用户目录。
该方法接受具有[标准用户目录属性](object#用户目录)的用户目录。

[comment]: # ({/9d471e91-d99c84a0})

[comment]: # ({b44a6c25-cd9247c6})
### 返回值

`(object)` 返回一个对象，该对象包含在`userdirectoryids`属性下创建的用户目录id。
返回的id的顺序与传递的用户目录的顺序匹配。

[comment]: # ({/b44a6c25-cd9247c6})

[comment]: # ({b41637d2-a15b0853})
### 示例

[comment]: # ({/b41637d2-a15b0853})

[comment]: # ({e1bcfdf7-36cc6d5c})

##### 创建一个用户目录

创建一个用户目录，以通过LDAP使用StartTLS对用户进行身份验证。
请注意，通过LDAP对用户进行身份验证时，[LDAP authentication](/manual/api/reference/authentication/object#认证对象)必须启用。

[请求](/manual/api#执行请求):

```json
{
    "jsonrpc": "2.0",
    "method": "userdirectory.create",
    "params": {
        "idp_type": "1",
        "name": "LDAP API server #1",
        "host": "ldap://local.ldap",
        "port": "389",
        "base_dn": "ou=Users,dc=example,dc=org",
        "bind_dn": "cn=ldap_search,dc=example,dc=org",
        "bind_password": "ldapsecretpassword",
        "search_attribute": "uid",
        "start_tls": "1"
    },
    "id": 1
}
```

响应:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "userdirectoryids": [
            "3"
        ]
    },
    "id": 1
}
```

[comment]: # ({/e1bcfdf7-36cc6d5c})

[comment]: # ({3b0bb38e-f354f485})
##### 创建一个用户目录 (已启用JIT设置)
创建用户目录以通过LDAP对用户进行身份验证 (已启用JIT设置)。
请注意，通过LDAP对用户进行身份验证时，[LDAP 身份认证](/manual/api/reference/authentication/object#认证对象)必须开启。

[请求](/manual/api#执行请求):

```json
{
    "jsonrpc": "2.0",
    "method": "userdirectory.create",
    "params": {
            "idp_type": "1",
            "name": "AD server",
            "provision_status": "1",
            "description": "",
            "host": "host.example.com",
            "port": "389",
            "base_dn": "DC=zbx,DC=local",
            "search_attribute": "sAMAccountName",
            "bind_dn": "CN=Admin,OU=Users,OU=Zabbix,DC=zbx,DC=local",
            "start_tls": "0",
            "search_filter": "",
            "group_basedn": "OU=Zabbix,DC=zbx,DC=local",
            "group_name": "CN",
            "group_member": "member",
            "group_filter": "(%{groupattr}=CN=%{ref},OU=Users,OU=Zabbix,DC=zbx,DC=local)",
            "group_membership": "",
            "user_username": "givenName",
            "user_lastname": "sn",
            "user_ref_attr": "CN",
            "provision_media": [
                {
                    "name": "example.com",
                    "mediatypeid": "1",
                    "attribute": "user@example.com"
                }
            ],
            "provision_groups": [
                {
                    "name": "*",
                    "roleid": "4",
                    "user_groups": [
                        {
                            "usrgrpid": "8"
                        }
                    ]
                },
                {
                    "name": "Zabbix administrators",
                    "roleid": "2",
                    "user_groups": [
                        {
                            "usrgrpid": "7"
                        },
                        {
                            "usrgrpid": "8"
                        }
                    ]
                }
            ]
        },
    "id": 1
}
```

响应:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "userdirectoryids": [
            "2"
        ]
    },
    "id": 1
}
```

[comment]: # ({/3b0bb38e-f354f485})

[comment]: # ({594536b5-8d17a3f4})
### 来源
CUserDirectory::create() in *ui/include/classes/api/services/CUserDirectory.php*.

[comment]: # ({/594536b5-8d17a3f4})
