Create or Update Group
This endpoint allows you to create a new group or update an existing group's information.
Endpoint Details
- URL:
/api/group - Method:
POST - Authentication: Required (creator role)
Request Parameters
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | integer | No | Group ID (include to update an existing group, omit to create a new one) |
| name | string | Yes | Name of the group |
| description | string | No | Description of the group |
| visibility | string | Yes | Privacy setting of the group (public, private, hidden) |
| coverImage | string | No | Filename of the group's cover image |
| purchaseLink | string | No | Optional link for purchasing access to the group |
| adminIds | array | No | Array of user IDs to be assigned as group admins |
Example Request
{
"name": "New Group",
"description": "This is a description of the new group",
"visibility": "private",
"adminIds": [23, 25]
}
Response
Success Response
- Code:
200 OK - Content: The created or updated group object
Example Response
{
"id": 135,
"name": "New Group",
"description": "This is a description of the new group",
"slug": "new-group",
"visibility": "private",
"purchaseLink": null,
"createdAt": "2022-05-18T10:30:45.000Z",
"updatedAt": "2022-05-18T10:30:45.000Z",
"PlatformId": 36,
"groupCreatorId": 9846
}
Error Response
- Code:
400 Bad Request - Content:
{ error: "Error message" }
Notes
- When updating a group, only include the fields you want to change.
- The
adminIdsarray will replace all existing admins with the new list. - The group slug is automatically generated from the name.
- Only users with creator privileges can create or update groups.
Code Examples
JavaScript
const createOrUpdateGroup = async groupData => {
try {
const response = await fetch("https://api.tribesocial.io/api/group", {
method: "POST",
headers: {
Authorization: "Bearer YOUR_TOKEN_HERE",
"Content-Type": "application/json"
},
body: JSON.stringify(groupData)
});
if (!response.ok) {
throw new Error("Failed to create/update group");
}
const group = await response.json();
return group;
} catch (error) {
console.error("Error creating/updating group:", error);
throw error;
}
};
// Example usage for creating a new group
const newGroup = {
name: "New Group",
description: "This is a description of the new group",
visibility: "private",
adminIds: [23, 25]
};
// Example usage for updating an existing group
const updatedGroup = {
id: 135,
name: "Updated Group Name",
visibility: "public"
};
Related Endpoints
- Get Group by Slug - Get detailed information about a specific group
- Remove User from Group - Remove a user from a group