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:45]
zalex_ua typos, correcting example, group names removed - unneeded at all
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 ​ ^ +''​(object/array)'' Users to create.
-|**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 ====+Additionally to the [[definitions#​user|standard user properties]],​ the method accepts the following parameters.
  
- Parameter ​  Description ​ +^ Parameter ^ Type ^ Description ^ 
-|**result**  |Operation successful. Result will contain array of created ​User IDs. **userid** are assigned to each User object  ​+| **passwd** \\ //​(required)//​ | string ​| User's password
-|**error**  ​|In case of any errors  ​|+**usrgrps** \\ (required) | array | User groups to add the user to. \\ \\ The user groups must have the ''​usrgrpid''​ property defined. ​
 +user_medias ​array Media to create for the user. \\ \\ The media ''​userid''​ property must not be defined. | 
 +==== Return values ====
  
-==== Example ==== +''​(object)''​ Returns an object containing the IDs of the created users under the ''​userids''​ propertyThe order of the returned IDs matches the order of the passed users.
-Create new user and added it to 2 user groupsPassword "​zabbix"​ will automatically be encoded by MD5 hash function.+
  
-<code js> +==== Examples ====
-+
-"​jsonrpc":"​2.0",​ +
-"​method":​ "​user.create",​ +
-"​params":​ [{ +
- "​usrgrps":​ [{ +
- "​usrgrpid":​ "​10009"​ +
- },{ +
- "​usrgrpid":​ "​10022"​ +
- }], +
- "​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:​+=== Creating a user ===
  
-<​code ​js>+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 \"Test User\" 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//​.