Remove User from Group
This endpoint allows you to remove a user from a specific group.
Endpoint Details
- URL:
/api/group/:id/user/:userId - Method:
DELETE - Authentication: Required (admin role for the group)
Request Parameters
URL Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | integer | Yes | The unique identifier for the group |
| userId | integer | Yes | The unique identifier for the user to remove |
Response
Success Response
- Code:
200 OK - Content: Success message
Example Response
{
"message": "User removed from group successfully"
}
Error Responses
-
Code:
400 Bad Request- Content:
{ error: "Error message" }
- Content:
-
Code:
403 Forbidden- Content:
"Insufficient role"
- Content:
-
Code:
404 Not Found- Content:
"Group not found"or"User not found in group"
- Content:
Notes
- Only group admins can remove users from a group.
- Users can remove themselves from a group (leave the group).
- Group creators cannot be removed from their own groups.
- When a user is removed, they lose access to all group content and collections.
Code Examples
JavaScript
const removeUserFromGroup = async (groupId, userId) => {
try {
const response = await fetch(`https://api.tribesocial.io/api/group/${groupId}/user/${userId}`, {
method: "DELETE",
headers: {
Authorization: "Bearer YOUR_TOKEN_HERE",
"Content-Type": "application/json"
}
});
if (response.status === 403) {
throw new Error("Insufficient permissions to remove user from group");
}
if (response.status === 404) {
throw new Error("Group or user not found");
}
if (!response.ok) {
throw new Error("Failed to remove user from group");
}
const result = await response.json();
return result;
} catch (error) {
console.error("Error removing user from group:", error);
throw error;
}
};
Related Endpoints
- Get Group by Slug - Get detailed information about a specific group
- Create or Update Group - Create a new group or update an existing group