Project

General

Profile

Rest Users » History » Version 14

Go MAEDA, 2016-05-09 02:58
Added api_key and status to example of response.

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
+Example+:
12
13 1 Jean-Philippe Lang
  GET /users.xml
14
15 10 Jean-Baptiste Barth
Optional filters:
16
17 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:
18
** @1@: Active (User can login and use their account)
19
** @2@: Registered (User has registered but not yet confirmed their email address or was not yet activated by an administrator. User can not login)
20
** @3@: Locked (User was once active and is now locked, User can not login)
21 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.
22
* @group_id@: get only users who are members of the given group
23
24 7 Jean-Philippe Lang
h3. POST
25 1 Jean-Philippe Lang
26 7 Jean-Philippe Lang
Creates a user.
27 1 Jean-Philippe Lang
28 7 Jean-Philippe Lang
+Parameters+:
29 1 Jean-Philippe Lang
30 7 Jean-Philippe Lang
* @user@ (required): a hash of the user attributes, including:
31 1 Jean-Philippe Lang
32 7 Jean-Philippe Lang
  * @login@ (required): the user login
33
  * @password@: the user password
34
  * @firstname@ (required)
35
  * @lastname@ (required)
36
  * @mail@ (required)
37
  * @auth_source_id@: authentication mode id
38 12 Matt Wiseley
  * @mail_notification@: only_my_events, none, etc.
39
  * @must_change_passwd@: true or false
40
41 1 Jean-Philippe Lang
42 7 Jean-Philippe Lang
+Example+:
43 1 Jean-Philippe Lang
44 7 Jean-Philippe Lang
<pre>
45
POST /users.xml
46
47
<?xml version="1.0" encoding="ISO-8859-1" ?>
48
<user>
49
  <login>jplang</login>
50
  <firstname>Jean-Philippe</firstname>
51
  <lastname>Lang</lastname>
52
  <password>secret</password>
53
  <mail>jp_lang@yahoo.fr</mail>
54
  <auth_source_id>2</auth_source_id>
55
</user>
56
</pre>
57
58 8 Lutz Horn
JSON
59
60
<pre>
61
{
62
    "user": {
63
        "login": "jplang",
64
        "firstname": "Jean-Philippe",
65
        "lastname": "Lang",
66
        "mail": "jp_lang@yahoo.fr",
67
        "password": "secret"
68
    }
69
}
70
</pre>
71
72 7 Jean-Philippe Lang
+Response+:
73
74
  * @201 Created@: user was created
75
  * @422 Unprocessable Entity@: user was not created due to validation failures (response body contains the error messages)
76
77
h2. /users/:id.:format
78
79
h3. GET
80
81
Returns the user details. You can use @/users/current.:format@ for retrieving the user whose credentials are used to access the API.
82
83 3 Jean-Philippe Lang
+Parameters+:
84 1 Jean-Philippe Lang
85
* @include@ (optional): a coma separated list of associations to include in the response:
86
87 11 Jean-Baptiste Barth
  * @memberships@ : adds extra information about user's memberships and roles on the projects
88
  * @groups@ (added in 2.1) : adds extra information about user's groups
89 1 Jean-Philippe Lang
90 7 Jean-Philippe Lang
+Examples+:
91 1 Jean-Philippe Lang
92 7 Jean-Philippe Lang
  GET /users/current.xml
93
94
Returns the details about the current user.
95
96 1 Jean-Philippe Lang
  GET /users/3.xml?include=memberships,groups
97
98
Returns the details about user ID 3, and additional detail about the user's project memberships.
99
100
+Reponse+:
101
102
<pre>
103
<user>
104
  <id>3</id>
105
  <login>jplang</login>
106
  <firstname>Jean-Philippe</firstname>
107
  <lastname>Lang</lastname>
108
  <mail>jp_lang@yahoo.fr</mail>
109
  <created_on>2007-09-28T00:16:04+02:00</created_on>
110
  <last_login_on>2011-08-01T18:05:45+02:00</last_login_on>
111 14 Go MAEDA
  <api_key>ebc3f6b781a6fb3f2b0a83ce0ebb80e0d585189d</api_key>
112
  <status>1</status>
113 5 Rick Mason
  <custom_fields type="array" />
114 1 Jean-Philippe Lang
  <memberships type="array">
115 4 Jean-Philippe Lang
    <membership>
116
      <project name="Redmine" id="1"/>
117
      <roles type="array">
118
        <role name="Administrator" id="3"/>
119
        <role name="Contributor" id="4"/>
120 1 Jean-Philippe Lang
      </roles>
121
    </membership>
122 4 Jean-Philippe Lang
  </memberships>
123
  <groups type="array">
124
    <group id="20" name="Developers"/>
125
  </groups>
126
</user>
127
</pre>
128
129 9 Jean-Baptiste Barth
Depending on the status of the user who makes the request, you can get some more details:
130
* @api_key@ : the API key of the user, visible for admins and for yourself (added in 2.3.0)
131
* @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.
132
133 7 Jean-Philippe Lang
h3. PUT
134 4 Jean-Philippe Lang
135 7 Jean-Philippe Lang
Updates a user.
136 4 Jean-Philippe Lang
137 1 Jean-Philippe Lang
+Example+:
138
139 7 Jean-Philippe Lang
  PUT /users/20.xml
140 1 Jean-Philippe Lang
141
+Parameters+:
142
143
* @user@ (required): a hash of the user attributes (same as for user creation)
144
145 7 Jean-Philippe Lang
h3. DELETE
146 1 Jean-Philippe Lang
147 7 Jean-Philippe Lang
Deletes a user.
148 4 Jean-Philippe Lang
149 7 Jean-Philippe Lang
+Example+:
150 1 Jean-Philippe Lang
151 7 Jean-Philippe Lang
  DELETE /users/20.xml
152 1 Jean-Philippe Lang
153
+Response+:
154 4 Jean-Philippe Lang
155
  * @200 OK@: user was deleted
156 7 Jean-Philippe Lang
157
h2. See also
158
159
* The [[Rest_Memberships|Memberships API]] for adding or removing a user from a project.
160
* The [[Rest_Groups|Groups API]] for adding or removing a user from a group.