Rest Users » History » Version 12

Matt Wiseley, 2014-12-13 18:12
Added 2 extra supported fieldsthat I had to look up in source code (mail_notification, must_change_passwd)

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