Updated on 2024-12-30 GMT+08:00

Creating a User

Function

This API is used to create a user.

Constraints

null

URI

POST /api/v2/tenant/users

Request Parameters

Table 1 Request header parameters

Parameter

Mandatory

Type

Description

Content-Type

Yes

String

Set this field to "application/json;charset=utf8".

Authorization

Yes

String

Authentication credential. The value is "Bearer {access_token}". access_token is obtained by calling the API for obtaining an access credential.

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

user_name

Yes

String

Username, which is a unique identifier in an enterprise. You can modify mandatory attributes on the User Attributes page under the Users menu on the administrator portal.

password

No

String

Password, which must be in the format defined by the enterprise.

mobile

Yes

String

Mobile number, which is unique in an enterprise. You can modify mandatory attributes on the User Attributes page under the Users menu on the administrator portal.

org_code

No

String

Main organization code. Enter an existing organization code in an enterprise. If the value is empty, the organization is under the first root organization.

name

No

String

Real name. If the value is null, which means it is set to user_name. You can modify mandatory attributes on the User Attributes page under the Users menu on the administrator portal.

email

No

String

Email address. You can modify mandatory attributes on the User Attributes page under the Users menu on the administrator portal.

employee_id

No

String

Employee ID. You can modify mandatory attributes on the User Attributes page under the Users menu on the administrator portal.

first_name

No

String

Name. You can modify mandatory attributes on the User Attributes page under the Users menu on the administrator portal.

middle_name

No

String

Middle name. You can modify mandatory attributes on the User Attributes page under the Users menu on the administrator portal.

last_name

No

String

Last name. You can modify mandatory attributes on the User Attributes page under the Users menu on the administrator portal.

pwd_must_modify

No

Boolean

Whether the password must be changed upon the first login.

attr_gender

No

String

Gender. You can modify mandatory attributes on the User Attributes page under the Users menu on the administrator portal.

attr_birthday

No

String

Date of birth. Format: yyyy-mm-dd. You can modify mandatory attributes on the User Attributes page under the Users menu on the administrator portal.

attr_nick_name

No

String

Alias. You can modify mandatory attributes on the User Attributes page under the Users menu on the administrator portal.

attr_identity_type

No

String

Certificate type.

attr_identity_number

No

String

Certificate number.

attr_area

No

String

Country or region code.

attr_city

No

String

City.

attr_manager_id

No

String

Immediate superior.

attr_user_type

No

String

Personnel type.

attr_hire_date

No

String

Onboarding date. Format: yyyy-MM-dd.

attr_work_place

No

String

Work location.

user_org_relation_list

No

Array of UserOrgRelationListOption objects

User organization relationship set. If you enter a value, the main organization information must be included.

extension

No

Object

Custom extended attribute.

Table 3 UserOrgRelationListOption

Parameter

Mandatory

Type

Description

orgCode

Yes

String

Organization code.

relationType

Yes

String

Ownership. A user only belongs to one organization and can be mounted to a maximum of nine organizations.

Response Parameters

Status code: 201

Table 4 Response body parameters

Parameter

Type

Description

user_id

String

User ID.

Status code: 400

Table 5 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error details.

Example Requests

Create a user whose username is zhangsan, mobile number is 12345678901, and email address is zhangsan@example.com.

POST https://{domain_name}/api/v2/tenant/users

Authorization: Bearer 334963fc-1e4a-473b-9096-52a929140...
{
    "user_name": "zhangsan",
    "password": "p******d",
    "org_code": "10000",
    "name": "zhangsan",
    "mobile": "12345678901",
    "email": "zhangsan@example.com",
    "employee_id": "123456789",
    "pwd_must_modify": false,
    "first_name": "F",
    "middle_name": "M",
    "last_name": "L",
    "attr_gender": "male",
    "attr_birthday": "1990-02-01",
    "attr_nick_name": "zhangsan",
    "attr_identity_type": "id_card",
    "attr_identity_number": "123456789",
    "attr_area": "CN",
    "attr_city": "xxx",
    "attr_manager_id": "123456789",
    "attr_user_type": "regular",
    "attr_hire_date": "2021-04-01",
    "attr_work_place": "xxx",
    "user_org_relation_list": [
      {
            "orgCode": "10000",
            "relationType": 1
      },
      {
            "orgCode": "TestOrg1",
            "relationType": 0
      },
      {
            "orgCode": "TestOrg2",
            "relationType": 0
      }
    ],
    "extension": {
        "age": "18"
    }
}

Example Responses

Status code: 201

Request successful.

{
  "user_id" : "20210621095935811-5E16-6B3060..."
}

Status Codes

Status Code

Description

201

Request successful.

400

Invalid parameter.

Error Codes

See Error Codes.