Project

General

Profile

Rest Memberships » History » Version 7

Jean-Philippe Lang, 2014-10-04 11:49

1 1 Jean-Philippe Lang
h1. Project Memberships
2
3
{{>toc}}
4
5
h2. /projects/:project_id/memberships.:format
6
7
h3. GET
8
9
Returns a paginated list of the project memberships. @:project_id@ can be either the project numerical id or the project identifier.
10
11
+Examples+:
12
13
<pre>
14
GET /projects/1/memberships.xml
15
GET /projects/redmine/memberships.xml
16
</pre>
17
18
+Response+:
19
20
<pre>
21
<?xml version="1.0" encoding="UTF-8"?>
22 4 Jean-Philippe Lang
<memberships type="array" limit="25" offset="0" total_count="3">
23 1 Jean-Philippe Lang
  <membership>
24
    <id>1</id>
25
    <project name="Redmine" id="1"/>
26
    <user name="David Robert" id="17"/>
27
    <roles type="array">
28
      <role name="Manager" id="1"/>
29
    </roles>
30
  </membership>
31
  <membership>
32
    <id>3</id>
33
    <project name="Redmine" id="1"/>
34
    <group name="Contributors" id="24"/>
35
    <roles type="array">
36
      <role name="Contributor" id="3"/>
37
    </roles>
38
  </membership>
39
  <membership>
40
    <id>4</id>
41
    <project name="Redmine" id="1"/>
42
    <user name="John Smith" id="27"/>
43
    <roles type="array">
44
      <role name="Developer" id="2" />
45
      <role name="Contributor" id="3" inherited="true" />
46
    </roles>
47
  </membership>
48
</memberships>
49
</pre>
50
51 3 Jean-Philippe Lang
Notes:
52 5 Jean-Philippe Lang
* The membership owner can be either a user or a group ([[Rest_Groups|Groups API]] is added in Redmine 2.1)
53 3 Jean-Philippe Lang
* In the above example, the @inherited="true"@ attribute on the last role means that this role was inherited from a group (eg. Jonh Smith belongs to the Contributors group and this group was added as a project member). John Smith's membership can not be deleted without deleting the group membership first.
54
* The memberships of a given user can be retrieved from the [[Rest_Users|Users API]].
55 1 Jean-Philippe Lang
56
h3. POST
57
58
Adds a project member.
59
60
+Parameters+:
61
62
* @membership@ (required): a hash of the membership attributes, including:
63
64 7 Jean-Philippe Lang
  * @user_id@ (required): the numerical id of the user or group
65 1 Jean-Philippe Lang
  * @role_ids@ (required): an array of roles numerical ids
66
67 2 Jean-Philippe Lang
+Example+:
68
69
<pre>
70
POST /projects/redmine/memberships.xml
71
72
<membership>
73
  <user_id>27</user_id>
74
  <role_ids type="array">
75
    <role_id>2</role_id>
76
  </role_ids>
77
</membership>
78
</pre>
79
80 6 Lutz Horn
JSON
81
82
<pre>
83
{
84
  "membership":
85
  {
86
    "user_id": 27,
87
    "role_ids": [ 2 ]
88
  }
89
}
90
</pre>
91
92 1 Jean-Philippe Lang
+Response+:
93
94
  * @201 Created@: membership was created
95
  * @422 Unprocessable Entity@: membership was not created due to validation failures (response body contains the error messages)
96
97
h2. /memberships/:id.:format
98
99
h3. GET
100
101
Returns the membership of given @:id@.
102
103
+Examples+:
104
105
<pre>
106
GET /memberships/1.xml
107
</pre>
108
109
+Response+:
110
111
<pre>
112
<?xml version="1.0" encoding="UTF-8"?>
113
<membership>
114
  <id>1</id>
115
  <project name="Redmine" id="1"/>
116
  <user name="David Robert" id="17"/>
117
  <roles type="array">
118
    <role name="Developer" id="2"/>
119
    <role name="Manager" id="1"/>
120
  </roles>
121
</membership>
122
</pre>
123
124
h3. PUT
125
126
Updates the membership of given :id. Only the roles can be updated, the project and the user of a membership are read-only.
127
128
+Parameters+:
129
130
* @membership@ (required): a hash of the membership attributes, including:
131
132
  * @role_ids@ (required): an array of roles numerical ids
133
134 2 Jean-Philippe Lang
+Example+:
135
136
<pre>
137
PUT /memberships/2.xml
138
139
<membership>
140
  <role_ids type="array">
141
    <role_id>3</role_id>
142
    <role_id>4</role_id>
143
  </role_ids>
144
</membership>
145
</pre>
146
147 1 Jean-Philippe Lang
+Response+:
148
149
  * @200 OK@: membership was updated
150
  * @422 Unprocessable Entity@: membership was not updated due to validation failures (response body contains the error messages)
151
152
h3. DELETE
153
154
Deletes a memberships.
155
156
Memberships inherited from a group membership can not be deleted. You must delete the group membership.
157
158
+Parameters+:
159
160
_none_
161 2 Jean-Philippe Lang
162
+Example+:
163
164
<pre>
165
DELETE /memberships/2.xml
166
</pre>
167 1 Jean-Philippe Lang
168
+Response+:
169
170
  * @200 OK@: membership was deleted
171
  * @422 Unprocessable Entity@: membership was not deleted