# Create user
This endpoint creates a user.
NOTE
In order to create a user, you need to create a role first. If you create a user without specifying the role UUID in the request, the request will result in an error. The create_user_role endpoint lets you create users.
Method | Path | Operation* |
---|---|---|
POST | /users | create_user |
*
In order for a user to perform the "create_user" operation, the "create_user" permission must be included in the list of allowed actions in the statement of the user's role.
# Request
Parameter | Type | In | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
name optional | string | body | Name of the user. It must match the regular expression(opens new window) ^[0-9A-Za-z][0-9A-Za-z_ \-]{0,30}[0-9A-Za-z]$ . It does not need to be unique in the context of the account. | ||||||||
role required | string | body | Role UUID. | ||||||||
description optional * | dictionary, DEFAULT=null | body | Attributes of the user in form of key-value pairs: - key: It must match the regular expression(opens new window) ^[a-z_][0-9a-z_]{0,63}$ .- value: JSON compliant value. For more details consult the description field section. | ||||||||
activity optional ** | dictionary, DEFAULT=null | body | User Activity Log attribute. It holds the name(s) of the Timeseries table(s) where the User Activity Log is to be stored, and (optionally) the |
Attribute | Type | In | Description |
---|---|---|---|
dimensions | dictionary | body | Key-value pairs: - key: name of the dimension under which the User Activity Log entry is to be stored. - value: Template for the value of the dimension. |
*
If no attributes are provided in the request body of "description"
("description": {}
), the response will return an empty dictionary ("description": {}
).
If "description"
with the value null
is provided in the request body, the response will not return the "description"
field.
If the request body does not contain "description"
, the response will not return the "description"
field.
**
The "activity"
attribute is optional. If not provided, the User Activity Log is not enabled for the given user.
In our example, we create the user "Oliver Adams"
with the role with the role UUID "9891264d-4a77-4fa2-ae7f-84c9af14ae3b"
and attributes in the "description"
field:
{
"name": "Oliver Adams",
"role": "cba1a586-b5b9-46f5-a99b-76f70404508f",
"description": {
"company": "Best Shoes",
"position": "accounting",
"in_house_payroll": true,
},
"activity": {
"user_activity_log": {
}
}
curl --location --request POST 'https://rest.trustedtwin.com/users' \
--header 'Authorization: VVNSC3bOfkVsVt/NsuQMr8VVJ+i0GTefQAcGjiu9V1TpqopWR75fC1W0pa10R3Gg' \
--header 'Content-Type: text/plain' \
--data-raw '{
"name": "Oliver Adams",
"role": "cba1a586-b5b9-46f5-a99b-76f70404508f",
"description": {
"company": "Best Shoes",
"position": "accounting",
"in_house_payroll": true
},
"activity": {
"user_activity_log": {
}
}
}'
from trustedtwin.tt_api import TTRESTService
TT_SERVICE = TTRESTService(
tt_auth="VVNSC3bOfkVsVt/NsuQMr8VVJ+i0GTefQAcGjiu9V1TpqopWR75fC1W0pa10R3Gg"
)
user_body = {
"name": "Oliver Adams",
"role": "cba1a586-b5b9-46f5-a99b-76f70404508f",
"description": {
"company": "Best Shoes",
"position": "accounting",
"in_house_payroll": True
},
"activity": {
"user_activity_log": {
}
}
}
status, response = TT_SERVICE.create_user(body=user_body)
import { UsersApi, Configuration } from "@trustedtwin/js-client";
var usersApi = new UsersApi(new Configuration({apiKey: "VVNSC3bOfkVsVt/NsuQMr8VVJ+i0GTefQAcGjiu9V1TpqopWR75fC1W0pa10R3Gg"}))
const userDefinition = await usersApi.createUser({
postNewUser: {
name: "Oliver Adams",
role: "cba1a586-b5b9-46f5-a99b-76f70404508f",
description: {
company: "Best Shoes",
position: "accounting",
inHousePayroll: true,
},
},
});
# Response
Attribute | Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
uuid | string | User UUID. | ||||||||
name | string | Name of the user. It must match the regular expression(opens new window) ^[0-9A-Za-z][0-9A-Za-z_ \-]{0,30}[0-9A-Za-z]$ . It does not need to be unique in the context of the account. | ||||||||
account | string | Account UUID. | ||||||||
role | string | Role UUID. | ||||||||
description | dictionary | Attributes of the user in form of key-value pairs: - key: It must match the regular expression(opens new window) ^[a-z_][0-9a-z_]{0,63}$ .- value: JSON compliant value. For more details consult the description field section. | ||||||||
created_ts | timestamp | Time at which the user was created. Measured in seconds (to three decimal places) that have elapsed since the Unix epoch(opens new window). | ||||||||
updated_ts | timestamp | Time at which the user was last updated. Measured in seconds (to three decimal places) that have elapsed since the Unix epoch(opens new window). | ||||||||
activity optional ** | dictionary | User Activity Log attribute. It holds the name(s) of the Timeseries table(s) where the User Activity Log is to be stored, and (optionally) the |
Attribute | Type | In | Description |
---|---|---|---|
dimensions | dictionary | body | Key-value pairs: - key: name of the dimension under which the User Activity Log entry is to be stored. - value: Template for the value of the dimension. |
{
"uuid":"3d0f1348-612a-4804-b632-24c4b871e76e",
"name":"Oliver Adams",
"account":"9891264d-4a77-4fa2-ae7f-84c9af14ae3b",
"role":"cba1a586-b5b9-46f5-a99b-76f70404508f",
"description":{
"company":"Best Shoes",
"position":"accounting",
"in_house_payroll":true
},
"activity":{
"user_activity_log":{
}
},
"created_ts":1646308575.845,
"updated_ts":1646308575.845
}
# Status codes
Requests to this endpoint result in generic status codes. For a comprehensive list of status codes, please consult the Status codes section.