Project

General

Profile

Rest Users » History » Version 20

Cyril Jouve, 2017-08-30 11:01

1 1 Jean-Philippe Lang
h1. Users
2
3 3 Jean-Philippe Lang
{{>toc}}
4
5 7 Jean-Philippe Lang
h2. /users.:format
6 1 Jean-Philippe Lang
7 7 Jean-Philippe Lang
h3. GET
8
9
Returns a list of users.
10
11 20 Cyril Jouve
This endpoint requires admin privileges.
12
13 7 Jean-Philippe Lang
+Example+:
14
15 1 Jean-Philippe Lang
  GET /users.xml
16
17 10 Jean-Baptiste Barth
Optional filters:
18
19 13 Go MAEDA
* @status@: get only users with the given status. See "app/models/principal.rb":/projects/redmine/repository/entry/trunk/app/models/principal.rb#L22-25 for a list of available statuses. Default is @1@ (active users). Possible values are:
20
** @1@: Active (User can login and use their account)
21
** @2@: Registered (User has registered but not yet confirmed their email address or was not yet activated by an administrator. User can not login)
22
** @3@: Locked (User was once active and is now locked, User can not login)
23 10 Jean-Baptiste Barth
* @name@: filter users on their login, firstname, lastname and mail ; if the pattern contains a space, it will also return users whose firstname match the first word or lastname match the second word.
24
* @group_id@: get only users who are members of the given group
25
26 7 Jean-Philippe Lang
h3. POST
27 1 Jean-Philippe Lang
28 7 Jean-Philippe Lang
Creates a user.
29 1 Jean-Philippe Lang
30 20 Cyril Jouve
This endpoint requires admin privileges.
31
32 7 Jean-Philippe Lang
+Parameters+:
33 1 Jean-Philippe Lang
34 7 Jean-Philippe Lang
* @user@ (required): a hash of the user attributes, including:
35 1 Jean-Philippe Lang
36 7 Jean-Philippe Lang
  * @login@ (required): the user login
37
  * @password@: the user password
38
  * @firstname@ (required)
39
  * @lastname@ (required)
40
  * @mail@ (required)
41
  * @auth_source_id@: authentication mode id
42 12 Matt Wiseley
  * @mail_notification@: only_my_events, none, etc.
43
  * @must_change_passwd@: true or false
44 19 F. P.
  * @generate_password@: true or false
45
* @send_information@: true or false : Send acocunt information to the user
46
47 1 Jean-Philippe Lang
48 7 Jean-Philippe Lang
+Example+:
49 1 Jean-Philippe Lang
50 17 Toshi MARUYAMA
<pre>
51 7 Jean-Philippe Lang
POST /users.xml
52 17 Toshi MARUYAMA
</pre>
53 1 Jean-Philippe Lang
54 16 Toshi MARUYAMA
<pre><code class="xml">
55 7 Jean-Philippe Lang
<?xml version="1.0" encoding="ISO-8859-1" ?>
56
<user>
57
  <login>jplang</login>
58
  <firstname>Jean-Philippe</firstname>
59
  <lastname>Lang</lastname>
60
  <password>secret</password>
61
  <mail>jp_lang@yahoo.fr</mail>
62
  <auth_source_id>2</auth_source_id>
63
</user>
64 16 Toshi MARUYAMA
</code></pre>
65 7 Jean-Philippe Lang
66 8 Lutz Horn
JSON
67
68 16 Toshi MARUYAMA
<pre><code class="json">
69 8 Lutz Horn
{
70
    "user": {
71
        "login": "jplang",
72
        "firstname": "Jean-Philippe",
73
        "lastname": "Lang",
74
        "mail": "jp_lang@yahoo.fr",
75
        "password": "secret"
76
    }
77
}
78 16 Toshi MARUYAMA
</code></pre>
79 8 Lutz Horn
80 7 Jean-Philippe Lang
+Response+:
81
82
  * @201 Created@: user was created
83
  * @422 Unprocessable Entity@: user was not created due to validation failures (response body contains the error messages)
84
85
h2. /users/:id.:format
86
87
h3. GET
88
89
Returns the user details. You can use @/users/current.:format@ for retrieving the user whose credentials are used to access the API.
90
91 20 Cyril Jouve
This endpoint can be used by admin or non admin but the returned fields will depend on the privileges of the requesting user.
92
93
If the user doing the request is admin, a complete user object is always returned (see exemple below).
94
95
If the user doing the request is not admin, it depends on the requested user:
96
97
  * if the user is not locked and is not admin, the endpoint returns a user object with the fields firstname, lastname, mail, created_on
98
  * if the user is not locked and is admin, the endpoint returns a user object with the fields firstname, lastname, created_on, last_login_on
99
  * if the user is locked, the endpoint returns 404 status code
100
101 3 Jean-Philippe Lang
+Parameters+:
102 1 Jean-Philippe Lang
103
* @include@ (optional): a coma separated list of associations to include in the response:
104
105 11 Jean-Baptiste Barth
  * @memberships@ : adds extra information about user's memberships and roles on the projects
106
  * @groups@ (added in 2.1) : adds extra information about user's groups
107 1 Jean-Philippe Lang
108 7 Jean-Philippe Lang
+Examples+:
109 1 Jean-Philippe Lang
110 7 Jean-Philippe Lang
  GET /users/current.xml
111
112
Returns the details about the current user.
113
114 1 Jean-Philippe Lang
  GET /users/3.xml?include=memberships,groups
115
116
Returns the details about user ID 3, and additional detail about the user's project memberships.
117
118 18 Toshi MARUYAMA
+Response+:
119 1 Jean-Philippe Lang
120 18 Toshi MARUYAMA
<pre><code class="xml">
121 1 Jean-Philippe Lang
<user>
122
  <id>3</id>
123
  <login>jplang</login>
124
  <firstname>Jean-Philippe</firstname>
125
  <lastname>Lang</lastname>
126
  <mail>jp_lang@yahoo.fr</mail>
127
  <created_on>2007-09-28T00:16:04+02:00</created_on>
128
  <last_login_on>2011-08-01T18:05:45+02:00</last_login_on>
129 14 Go MAEDA
  <api_key>ebc3f6b781a6fb3f2b0a83ce0ebb80e0d585189d</api_key>
130
  <status>1</status>
131 5 Rick Mason
  <custom_fields type="array" />
132 1 Jean-Philippe Lang
  <memberships type="array">
133 4 Jean-Philippe Lang
    <membership>
134
      <project name="Redmine" id="1"/>
135
      <roles type="array">
136
        <role name="Administrator" id="3"/>
137
        <role name="Contributor" id="4"/>
138 1 Jean-Philippe Lang
      </roles>
139
    </membership>
140 4 Jean-Philippe Lang
  </memberships>
141
  <groups type="array">
142
    <group id="20" name="Developers"/>
143
  </groups>
144
</user>
145 18 Toshi MARUYAMA
</code></pre>
146 4 Jean-Philippe Lang
147 9 Jean-Baptiste Barth
Depending on the status of the user who makes the request, you can get some more details:
148
* @api_key@ : the API key of the user, visible for admins and for yourself (added in 2.3.0)
149
* @status@ : a numeric id representing the status of the user, visible for admins only (added in 2.4.0). See "app/models/principal.rb":/projects/redmine/repository/entry/trunk/app/models/principal.rb#L22-25 for a list of available statuses.
150
151 7 Jean-Philippe Lang
h3. PUT
152 4 Jean-Philippe Lang
153 7 Jean-Philippe Lang
Updates a user.
154 4 Jean-Philippe Lang
155 20 Cyril Jouve
This endpoint requires admin privileges.
156
157 1 Jean-Philippe Lang
+Example+:
158
159 7 Jean-Philippe Lang
  PUT /users/20.xml
160 1 Jean-Philippe Lang
161
+Parameters+:
162
163
* @user@ (required): a hash of the user attributes (same as for user creation)
164
165 7 Jean-Philippe Lang
h3. DELETE
166 20 Cyril Jouve
167
This endpoint requires admin privileges.
168 1 Jean-Philippe Lang
169 7 Jean-Philippe Lang
Deletes a user.
170 4 Jean-Philippe Lang
171 7 Jean-Philippe Lang
+Example+:
172 1 Jean-Philippe Lang
173 7 Jean-Philippe Lang
  DELETE /users/20.xml
174 1 Jean-Philippe Lang
175
+Response+:
176 4 Jean-Philippe Lang
177
  * @200 OK@: user was deleted
178 7 Jean-Philippe Lang
179
h2. See also
180
181
* The [[Rest_Memberships|Memberships API]] for adding or removing a user from a project.
182
* The [[Rest_Groups|Groups API]] for adding or removing a user from a group.