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 [2011/06/15 20:53]
zalex_ua added "js" to code blocs
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 ==== +
-Create new user and added it to 3 user groups. Password "​zabbix"​ will automaticly be encoded by MD5 hash function.+
  
-<code js> +Additionally to the [[definitions#​user|standard user properties]], the method accepts the following parameters.
-+
-"​jsonrpc":"​2.0",​ +
-"​method":"​user.create",​ +
-"​params":​[+
- "​usrgrps":​[+
- "​usrgrpid":"​100100000000009",​ +
- "​name":"​Internal login"​ +
- },{ +
- "​usrgrpid":"​100100000000020",​ +
- "​name":"​API access"​ +
- },{ +
- "​usrgrpid":"​100100000000022",​ +
- "​name":"​Debug group"​ +
- }], +
- "​alias":"​Test User",​ +
- "​name":"​Test User Name",​ +
- "​surname":"​Test User Surname",​ +
- "​passwd":"​zabbix",​ +
- "​url":"",​ +
- "​autologin":"​0",​ +
- "​autologout":"​600",​ +
- "​lang":"​en_gb",​ +
- "​refresh":"​90",​ +
- "​type":"​1",​ +
- "​theme":"​css_ob.css",​ +
- "​attempt_failed":"​0",​ +
- "​attempt_ip":"",​ +
- "​attempt_clock":"​0",​ +
- "​rows_per_page":"​50"​ +
-}], +
-"​auth":"​038e1d7b1735c6a5436ee9eae095879e",​ +
-"​id":​3 +
-+
-</​code>​+
  
-User added successfully:​+^ Parameter ^ Type ^ Description ^ 
 +| **passwd** \\ //​(required)//​ | string | User's password. | 
 +| **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 ====
  
-<​code ​js>+''​(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. 
 + 
 +==== 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": ["107819"] +    "​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":"​[ CUser::​create ​User [ 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//​.