Skip to main content

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

ParameterTypeRequiredDescription
platformIdintegerYesThe unique identifier for the platform

Query Parameters

ParameterTypeRequiredDescription
pageintegerNoPage number for pagination (default: 1)
limitintegerNoNumber of items per page (default: 25)
searchstringNoSearch term to filter groups

Response

Success Response

  • Code: 200 OK
  • Content: Paginated list of groups belonging to the platform

Response Fields

FieldTypeDescription
itemsarrayArray of group objects
itemsPerPageintegerNumber of items per page
currentPageintegerCurrent page number
totalItemsintegerTotal number of items across all pages
totalPagesintegerTotal number of pages
searchTermstringSearch term used (if any)
hasMorebooleanWhether there are more pages available

Group Object Fields

FieldTypeDescription
idintegerUnique identifier for the group
namestringName of the group
descriptionstringDescription of the group (can be null)
slugstringURL-friendly identifier for the group
coverImagestringFilename of the group's cover image
visibilitystringPrivacy setting of the group
purchaseLinkstringOptional link for purchasing access to the group
createdAtstringISO timestamp of when the group was created
updatedAtstringISO timestamp of when the group was last updated
PlatformIdintegerID of the platform the group belongs to
groupCreatorIdintegerID of the user who created the group
userCountintegerNumber 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" }
  • Code: 403 Forbidden

    • Content: "Insufficient role"
  • Code: 404 Not Found

    • Content: "Platform not found"

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;
}
};