Create or Update Collection
This endpoint creates a new collection or updates an existing one.
Endpoint
POST /api/collection
Authentication
Authentication is required. User must have admin or creator role.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
id | Integer | No | Collection ID (include for updates, omit for creation) |
name | String | Yes | Display name of the collection |
description | String | No | Rich text description of the collection |
slug | String | Yes | URL-friendly identifier for the collection |
collectionBGImage | String | No | Background image filename |
position | Integer | No | Order position for display |
expireDate | Date | No | Date when the collection expires |
publishedDate | Date | No | Date when the collection is published |
collectionType | String | No | Type of collection (default: "default") |
sortPreference | String | No | How content should be sorted (e.g., "most recent first") |
PlatformId | Integer | Yes | ID of the platform this collection belongs to |
UserId | Integer | No | ID of the user creating this collection |
showOnHomepage | Boolean | No | Whether to show on homepage |
GroupIds | Array | No | Array of group IDs to associate with this collection |
ContentIds | Array | No | Array of content IDs to set positions for |
Response
Success Response
- Status Code: 200 OK
- Content: Array containing the collection object and a boolean indicating if it's a new record
[
{
"id": 123,
"name": "Workshop Sessions",
"description": "<p>All workshop sessions from our recent event.</p>",
"slug": "workshop-sessions",
"collectionBGImage": "background-image.png",
"position": 1,
"expireDate": null,
"publishedDate": null,
"collectionType": "default",
"sortPreference": "most recent first",
"createdAt": "2022-01-15T19:24:52.000Z",
"updatedAt": "2022-03-03T06:42:31.000Z",
"PlatformId": 36,
"UserId": 456,
"Platform": {
"id": 36,
"name": "Example Platform",
"slug": "example"
// Additional platform properties...
}
},
true // Indicates this is a new record (false for updates)
]
Error Response
- Status Code: 403 Forbidden
- Content: Error message if the user doesn't have permission
{
"error": "Access denied"
}
- Status Code: 500 Internal Server Error
- Content: Error message for server errors
{
"error": "Something went wrong"
}
Notes
- When updating a collection, the user must be an admin or the creator of the collection.
- When creating a collection, the
PlatformIdmust match the user's platform. - If
GroupIdsis provided, the collection will be associated with those groups. - If
ContentIdsis provided, the positions of those content items within the collection will be updated. - The collection is also synchronized with Firebase Firestore for use in the mobile application.
- Content positions are determined by the order of IDs in the
ContentIdsarray.
Example
# Create a new collection
curl -X POST "https://api.tribesocial.io/api/collection" \
-H "Authorization: Bearer YOUR_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "New Workshop Series",
"description": "<p>Our latest workshop series.</p>",
"slug": "new-workshop-series",
"PlatformId": 36,
"sortPreference": "most recent first",
"showOnHomepage": true,
"GroupIds": [1, 2, 3]
}'
# Update an existing collection
curl -X POST "https://api.tribesocial.io/api/collection" \
-H "Authorization: Bearer YOUR_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"id": 123,
"name": "Updated Workshop Series",
"description": "<p>Our updated workshop series.</p>",
"slug": "updated-workshop-series",
"PlatformId": 36,
"ContentIds": [101, 102, 103]
}'