This API helps you add or modify a user's role on a resource.
The role that you want to assign a user should be a subset of the role that you have on the resource. To get all roles that can be assigned to a user on a resource, user should call Get Roles that can be Assigned to a User on a Resource.
You must be a resource owner, Administrator or a super user to add or modify a role. You must also have Read privilege on User ID and Role ID.
The syntax for calling this method is:
PUT <Base_Url/>resource/user/{userId}/role/{roleId}
A sample API call is as follows:
PUT https://123.123.123.123/vCenter-CB/api/resource/user/user1/role/15
The request XML for this API contains the following parameters .
XPath |
Type |
Min Occurs |
Max Occurs |
Description |
---|---|---|---|---|
Resources/Resource |
|
1 |
unbounded |
Represents the resources. |
Resources/Resource/@id |
xs:int |
1 |
1 |
ID of the resource on which you want to apply the role. |
A sample request is provided here.
If the operation is successful, the API gets an XML response with the following details.
XPath |
Type |
Min Occurs |
Max Occurs |
Description |
---|---|---|---|---|
Users/User |
|
1 |
1 |
This is the user element. |
Users/User/@id |
xs:string |
1 |
1 |
ID of the user. |
Users/User/Name |
xs:string |
1 |
1 |
Name of the user. |
Roles/Role |
|
1 |
1 |
This is the role element. |
Roles/Role/@id |
xs:int |
1 |
1 |
ID of the user role. |
Roles/Role/Name |
xs:string |
1 |
1 |
Name of the user role. |
Roles/Role/Description |
xs:string |
1 |
1 |
Description provided for the user role. |
Roles/Role/Custom |
xs:boolean |
|
|
Indicates whether the role is a custom role. |
Roles/Role/Privileges/Privilege |
|
1 |
unbounded |
This is privilege element. |
Roles/Role/Privileges/Privilege/@id |
xs:int |
1 |
1 |
The unique ID of the privilege the user role is assigned. |
Resources/Resource/ |
|
|
|
Represents the Resources. |
Resources/Resource/@id |
xs:int |
1 |
1 |
ID of the resource. |
A sample response is provided here.
The following table explains the error codes displayed by the API.
Error code |
Description |
VCENTER_COMMON_ERR_INSUFFICIENT_PERMISSION |
User does not have sufficient permissions for performing this operation. |
VCENTER_COMMON_ERR_USER_NOT_AUTHENTICATED |
User is not authenticated to perform this operation. |
VCB_ERR_USER_NOT_FOUND |
No user exists with the given User ID. |
VCB_ERR_ROLE_NOT_FOUND |
No role exists with the given Role ID. |
VCB_ERR_RESOURCE_NOT_FOUND |
No resource exists with the given Resource ID. |