Zabbix Documentation 2.0

3.04.05.0 (current)| In development:5.2 (devel)| Unsupported:1.82.02.22.43.23.44.24.4Guidelines

User Tools

Site Tools


manual:appendix:api:user:create

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
manual:appendix:api:user:create [2012/04/16 15:31]
zalex_ua added escaping in example. deleted illogical parameters from example, reordering
manual:appendix:api:user:create [2019/01/28 14:49] (current)
sasha <code js> => <code java>
Line 1: Line 1:
-===== create() ===== +===== user.create ===== 
-This function allows you to create a user as defined by the **user data** array. Available only to super admins.+ 
 +==== Description ==== 
 + 
 +''​object ​user.create(object/​array ​**users**)''​ 
 + 
 +This method allows ​to create new users.
  
 ==== Parameters ==== ==== Parameters ====
-^  Parameter ​ ^  Type  ^  Optional ​ ^  Description ​ ^  Details ​ ^ 
-|**user data** ​ |//array or object// ​ |No  |Array of User objects or a single object ​ |**userid** shouldn'​t be specified ​ | 
-|**usrgrps** ​ |//​array// ​ |No  |User Groups add User to.  |  | 
-|**user_medias** ​ |//​array// ​ |No  |Create User Medias for User.  |  | 
  
-==== Returns ==== +''​(object/​array)''​ Users to create.
-^  Parameter ​ ^  Description ​ ^ +
-|**result** ​ |Operation successful. Result will contain ​array of created User IDs**userid** are assigned to each User object ​ | +
-|**error** ​ |In case of any errors ​ |+
  
-==== Example ==== +Additionally ​to the [[definitions#​user|standard ​user properties]],​ the method accepts the following parameters.
-Create new user and added it to user groups. Password "​zabbix"​ will automaticly be encoded by MD5 hash function.+
  
-<code js> +^ Parameter ^ Type ^ Description ^ 
-+| **passwd** \\ //​(required)//​ | string | User's password| 
-"​jsonrpc":"​2.0", +| **usrgrps** \\ (required) | array | User groups to add the user to\\ \\ The user groups must have the ''​usrgrpid''​ property defined. | 
-"​method":​ "user.create",​ +| user_medias | array | Media to create for the user. \\ \\ The media ''​userid''​ property must not be defined. | 
-"​params":​ [{ +==== Return values ====
- "​usrgrps":​ [{ +
- "usrgrpid": "​10009",​ +
- "​name":​ "​Internal login" +
- },{ +
- "​usrgrpid":​ "​10020",​ +
- "​name":​ "API access"​ +
- },{ +
- "​usrgrpid":​ "​10022",​ +
- "​name":​ "Debug group"​ +
- }], +
- "​type":​ "​1",​ +
- "​alias":​ "Test User",​ +
- "​name":​ "Test User Name",​ +
- "​surname":​ "Test User Surname",​ +
- "​passwd":​ "​zabbix",​ +
- "​lang":​ "​en_GB",​ +
- "​theme":​ "​originalblue",​ +
- "​autologin":​ "​0",​ +
- "​autologout":​ "​600",​ +
- "​refresh":​ "​90",​ +
- "​rows_per_page":​ "​50",​ +
- "​url":​ ""​ +
-}], +
-"​auth":​ "​038e1d7b1735c6a5436ee9eae095879e",​ +
-"​id":​ 3 +
-+
-</​code>​+
  
-User added successfully:​+''​(object)''​ Returns an object containing the IDs of the created users under the ''​userids''​ property. The order of the returned IDs matches the order of the passed users.
  
-<​code ​js>+==== Examples ==== 
 + 
 +=== Creating a user === 
 + 
 +Create a new user, add him to a user group and create a new media for him. 
 + 
 +Request: 
 +<​code ​java>
 { {
-"​jsonrpc":​ "​2.0",​ +    ​"​jsonrpc":​ "​2.0",​ 
-"result": { +    "method":​ "​user.create",​ 
-   ​"userids": ["10819"] +    "​params": { 
-}, +        "alias":​ "​John",​ 
-"​id": ​3+        "​passwd":​ "​Doe123",​ 
 +        "​usrgrps": [ 
 +            { 
 +                ​"usrgrpid": "​7"​ 
 +            } 
 +        ​], 
 +        "​user_medias":​ [ 
 +            { 
 +                "​mediatypeid":​ "​1",​ 
 +                "​sendto":​ "​[email protected]",​ 
 +                "​active":​ 0, 
 +                "​severity":​ 63, 
 +                "​period":​ "​1-7,​00:​00-24:​00"​ 
 +            ​} 
 +        ] 
 +    }, 
 +    "​auth":​ "​038e1d7b1735c6a5436ee9eae095879e"​
 +    "​id": ​1
 } }
 </​code>​ </​code>​
  
-User already exists: +Response
- +<​code ​java>
-<​code ​js>+
 { {
-"​jsonrpc":​ "​2.0",​ +    ​"​jsonrpc":​ "​2.0",​ 
-"error": { +    "result": { 
-      "code": ​-32602, +        "userids": ​[ 
-      "message": "​Invalid params.",​ +            "12
-      "​data":​ "User with alias \"​Admin\"​ already exists."​ +        ] 
-}, +    }, 
-"​id": ​3+    "​id": ​1
 } }
 </​code>​ </​code>​
 +
 +==== See also ====
 +
 +  * [[manual:​appendix:​api:​usermedia:​definitions#​media|Media]]
 +  * [[manual:​appendix:​api:​usergroup:​definitions#​user_group|User group]]
 +
 +
 +==== Source ====
 +
 +CUser::​create() in //​frontends/​php/​api/​classes/​CUser.php//​.