<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[API: Is there a way to add a single user to a group without replacing all members?]]></title><description><![CDATA[<p dir="auto">Hi all,</p>
<p dir="auto">We want to set Groups for Users via the API, as far as I can tell, there are two ways to change group membership:</p>
<ol>
<li>PUT /api/v1/groups/:groupId/members with { "userIds":  }</li>
<li>PUT /api/v1/users/:userId/groups with { "groupIds": [...] }</li>
</ol>
<p dir="auto">Looking at src/groups.js, both seem to replace rather than add:</p>
<ul>
<li>setMembers() first runs DELETE FROM groupMembers WHERE groupId = ? and then inserts only the userIds from the request.</li>
<li>setLocalMembership() first removes the user from all local groups and then inserts only the groupIds from the request.</li>
</ul>
<p dir="auto">-&gt; This means we cant just Add a new user to a Groupe via API correct? We woud always have to first get the Group then take all the listed useres Append the new users and run the Put groups API with the Appended list - or do the same with all current groups from a user?</p>
]]></description><link>https://forum.cloudron.io/topic/16346/api-is-there-a-way-to-add-a-single-user-to-a-group-without-replacing-all-members</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Dec 2026 17:25:24 GMT</lastBuildDate><atom:link href="https://forum.cloudron.io/topic/16346.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 27 Nov 2026 11:26:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to API: Is there a way to add a single user to a group without replacing all members? on Fri, 27 Nov 2026 12:10:51 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/n0ah" aria-label="Profile: n0ah">@<bdi>n0ah</bdi></a></p>
<p dir="auto">Correct, both calls replace the full list. There is no endpoint that adds or removes a single member.</p>
<ul>
<li><code>PUT /api/v1/groups/:groupId/members</code> replaces all members of that group.</li>
<li><code>PUT /api/v1/users/:userId/groups</code> replaces that user's memberships in local groups.<br />
Memberships in external LDAP groups are left alone.</li>
</ul>
<p dir="auto">So it is read, modify, write.<br />
I would use the per-user endpoint, since it only changes that one user.<br />
With <code>/groups/:groupId/members</code>, two clients adding different users to the same group at the same time can overwrite each other.</p>
<pre><code class="language-bash">USER_ID=uid-xxx
GROUP_ID=gid-yyy

CURRENT=$(curl -s -H "Authorization: Bearer $TOKEN" "https://my.example.com/api/v1/users/$USER_ID" | yq -p json -o json -I0 '.groupIds')

curl -X PUT -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  "https://my.example.com/api/v1/users/$USER_ID/groups" \
  -d "{\"groupIds\": $(echo "$CURRENT" | yq -p json -o json -I0 ". + [\"$GROUP_ID\"] | unique")}"</code></pre>
]]></description><link>https://forum.cloudron.io/post/133467</link><guid isPermaLink="true">https://forum.cloudron.io/post/133467</guid><dc:creator><![CDATA[james]]></dc:creator><pubDate>Fri, 27 Nov 2026 12:10:51 GMT</pubDate></item></channel></rss>