Get Groups by Platform ID
This endpoint retrieves all groups that belong to a specific platform, identified by the platform's ID.
Endpoint Details
- URL:
/api/groups/platform/:platformId - Method:
GET - Authentication: Required (admin role for the platform)
Request Parameters
URL Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| platformId | integer | Yes | The unique identifier for the platform |
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| page | integer | No | Page number for pagination (default: 1) |
| limit | integer | No | Number of items per page (default: 25) |
| search | string | No | Search term to filter groups |
Response
Success Response
- Code:
200 OK - Content: Paginated list of groups belonging to the platform
Response Fields
| Field | Type | Description |
|---|---|---|
| items | array | Array of group objects |
| itemsPerPage | integer | Number of items per page |
| currentPage | integer | Current page number |
| totalItems | integer | Total number of items across all pages |
| totalPages | integer | Total number of pages |
| searchTerm | string | Search term used (if any) |
| hasMore | boolean | Whether there are more pages available |
Group Object Fields
| Field | Type | Description |
|---|---|---|
| id | integer | Unique identifier for the group |
| name | string | Name of the group |
| description | string | Description of the group (can be null) |
| slug | string | URL-friendly identifier for the group |
| coverImage | string | Filename of the group's cover image |
| visibility | string | Privacy setting of the group |
| purchaseLink | string | Optional link for purchasing access to the group |
| createdAt | string | ISO timestamp of when the group was created |
| updatedAt | string | ISO timestamp of when the group was last updated |
| PlatformId | integer | ID of the platform the group belongs to |
| groupCreatorId | integer | ID of the user who created the group |
| userCount | integer | Number of users in the group |
Example Response
{
"items": [
{
"id": 134,
"name": "private group",
"description": null,
"slug": "private-group",
"coverImage": "1652800675986.jpg",
"visibility": "private",
"purchaseLink": null,
"createdAt": "2022-05-17T04:51:15.000Z",
"updatedAt": "2022-05-17T15:18:06.000Z",
"PlatformId": 36,
"groupCreatorId": 9846,
"userCount": 3
},
{
"id": 135,
"name": "public group",
"description": "This is a public group",
"slug": "public-group",
"coverImage": "1652800675987.jpg",
"visibility": "public",
"purchaseLink": null,
"createdAt": "2022-05-17T05:30:20.000Z",
"updatedAt": "2022-05-17T15:20:10.000Z",
"PlatformId": 36,
"groupCreatorId": 9846,
"userCount": 15
}
],
"itemsPerPage": 25,
"currentPage": 1,
"totalItems": 2,
"totalPages": 1,
"searchTerm": "",
"hasMore": false
}
Error Responses
-
Code:
400 Bad Request- Content:
{ error: "Error message" }
- Content:
-
Code:
403 Forbidden- Content:
"Insufficient role"
- Content:
-
Code:
404 Not Found- Content:
"Platform not found"
- Content:
Notes
- This endpoint is typically used by platform administrators to manage all groups within their platform.
- The response includes all groups regardless of visibility settings.
- The response is paginated, with a default of 25 items per page.
Code Examples
JavaScript
const getGroupsByPlatformId = async (platformId, page = 1, limit = 25, search = "") => {
try {
const queryParams = new URLSearchParams({
page,
limit,
...(search && { search })
}).toString();
const response = await fetch(
`https://api.tribesocial.io/api/groups/platform/${platformId}?${queryParams}`,
{
method: "GET",
headers: {
Authorization: "Bearer YOUR_TOKEN_HERE",
"Content-Type": "application/json"
}
}
);
if (response.status === 403) {
throw new Error("Insufficient permissions to access platform groups");
}
if (response.status === 404) {
throw new Error("Platform not found");
}
if (!response.ok) {
throw new Error("Failed to fetch platform groups");
}
const groups = await response.json();
return groups;
} catch (error) {
console.error("Error fetching platform groups:", error);
throw error;
}
};
Related Endpoints
- Get My Groups - Get all groups where the user is a member
- Get Group by Slug - Get detailed information about a specific group