Help Center/ Workspace/ API Reference/ Workspace APIs/ Desktop/ Assigning a Desktop to a User
Updated on 2025-07-14 GMT+08:00

Assigning a Desktop to a User

Function

Assigns a desktop to a user.

Debugging

You can debug this API through automatic authentication in API Explorer or use the SDK sample code generated by API Explorer.

URI

POST /v2/{project_id}/desktops/attach

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

No

String

User token.

It can be obtained by calling the IAM API that is used to obtain a user token. The value of X-Subject-Token in the response header is the user token.

Content-Type

No

String

MIME type of the request body.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

desktops

No

Array of AttachInstancesDesktopInfo objects

Desktop information list.

image_type

No

String

Image type. This parameter is mandatory only when the image needs to be changed.

image_id

No

String

Template ID: This parameter is mandatory only when the image needs to be changed.

desktop_name_policy_id

No

String

Policy ID, which is used to specify a policy for generating desktop names. If a desktop name is specified, the specified desktop name is used preferentially.

Table 4 AttachInstancesDesktopInfo

Parameter

Mandatory

Type

Description

desktop_id

No

String

ID of the desktop to be assigned.

user_name

No

String

User to whom a desktop belongs. After a desktop is assigned, the user can log in to the desktop. Only letters, digits, hyphens (-), and underscores (_) are allowed. When the domain type is LITE_AD, the value contains 1 to 20 characters starting with a letter. When the domain type is LOCAL_AD, the value contains 1 to 32 characters starting with a letter or digit. A Windows desktop username can contain a maximum of 20 characters, and a Linux desktop username can contain a maximum of 32 characters. The username cannot be the same as the name of the assigned desktop. This parameter is mandatory when attach_user_infos is left blank. attach_user_infos has a higher priority.

user_email

No

String

Valid user email. After a desktop is assigned, a notification will be emailed to the user.

user_group

No

String

User group to which the desktop user belongs. This parameter is mandatory when attach_user_infos is left blank. attach_user_infos has a higher priority.

  • sudo: Linux administrator group

  • default: default Linux user group

  • administrators: Windows administrator group. Administrators have full access to the desktop and can make any required changes except for forbidden operations.

  • users: standard Windows user group. Standard users can use most software programs and change system settings that do not affect other users.

computer_name

No

String

Desktop name, which must be unique. Enter 1 to 15 characters of only letters, digits, hyphens (-), and underscores (_). It must start with a letter and cannot end with a hyphen (-).

is_clear_data

No

Boolean

This parameter is valid only when unbinding and binding are performed on the same user. Whether to clear desktop data during binding. The options are true (yes) and false (no). The default value is true.

attach_user_infos

No

Array of AttachInstancesUserInfo objects

List of users to whom desktops are to be assigned. This parameter is valid only when a multi-user desktop is assigned to multiple users.

Table 5 AttachInstancesUserInfo

Parameter

Mandatory

Type

Description

user_id

No

String

If type is set to USER, enter the user ID. If type is set to GROUP, enter the user group ID. The backend service checks whether the group ID exists.

user_name

No

String

Name of the object assigned with a desktop. If type is set to USER, enter the username. If type is set to GROUP, enter the user group name.

  • If type is set to USER, the value is the username of the desktop user. After the desktop is assigned, the user can log in to the desktop. Only letters, digits, hyphens (-), and underscores (_) are allowed. When the domain type is LITE_AD, the value contains 1 to 20 characters starting with a letter. When the domain type is LOCAL_AD, the value contains 1 to 64 characters starting with a letter or digit. A Windows desktop username can contain a maximum of 20 characters, and a Linux desktop username can contain a maximum of 64 characters. The backend service checks whether the username exists. The username cannot be the same as the desktop name.

  • If type is set to GROUP, the value can contain only letters, digits, hyphens (-), and underscores (_).

user_group

No

String

Specifies the user group to which the desktop user belongs.

  • sudo: Linux administrator group.

  • default: default Linux user group.

  • administrators: Windows administrator group. Administrators have full access to the desktop and can make any required changes except for forbidden operations.

  • users: standard Windows user group. Standard users can use most software programs and change system settings that do not affect other users.

type

No

String

Object type. Options:

  • USER: user

  • GROUP: user group

Response Parameters

Status code: 200

Table 6 Response body parameters

Parameter

Type

Description

job_id

String

ID of the cloud desktop assignment task.

Status code: 400

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Error code, which is returned upon failure.

error_msg

String

Error description.

error_detail

String

Error details.

encoded_authorization_message

String

Encrypted detailed reason for rejection. You can call the API decode-authorization-message of STS to decrypt the reason.

Status code: 401

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Error code, which is returned upon failure.

error_msg

String

Error description.

error_detail

String

Error details.

encoded_authorization_message

String

Encrypted detailed reason for rejection. You can call the API decode-authorization-message of STS to decrypt the reason.

Status code: 403

Table 9 Response body parameters

Parameter

Type

Description

error_code

String

Error code, which is returned upon failure.

error_msg

String

Error description.

error_detail

String

Error details.

encoded_authorization_message

String

Encrypted detailed reason for rejection. You can call the API decode-authorization-message of STS to decrypt the reason.

Status code: 404

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

Error code, which is returned upon failure.

error_msg

String

Error description.

error_detail

String

Error details.

encoded_authorization_message

String

Encrypted detailed reason for rejection. You can call the API decode-authorization-message of STS to decrypt the reason.

Status code: 409

Table 11 Response body parameters

Parameter

Type

Description

error_code

String

Error code, which is returned upon failure.

error_msg

String

Error description.

error_detail

String

Error details.

encoded_authorization_message

String

Encrypted detailed reason for rejection. You can call the API decode-authorization-message of STS to decrypt the reason.

Status code: 500

Table 12 Response body parameters

Parameter

Type

Description

error_code

String

Error code, which is returned upon failure.

error_msg

String

Error description.

error_detail

String

Error details.

encoded_authorization_message

String

Encrypted detailed reason for rejection. You can call the API decode-authorization-message of STS to decrypt the reason.

Example Requests

{
  "desktops" : [ {
    "desktop_id" : "string",
    "user_name" : "string",
    "user_group" : "string",
    "computer_name" : "string",
    "is_clear_data" : "true"
  } ],
  "image_type" : "string",
  "image_id" : "string",
  "desktop_name_policy_id" : "string"
}

Example Responses

Status code: 200

Normal.

{
  "job_id" : "string"
}

Status Codes

Status Code

Description

200

Normal.

400

The request cannot be understood by the server due to malformed syntax.

401

Authentication failed.

403

No operation permissions.

404

No resources found.

409

Operation conflict.

500

An internal service error occurred. For details, see the error code description.

Error Codes

See Error Codes.