Skip to main content

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

FieldTypeRequiredDescription
idIntegerNoCollection ID (include for updates, omit for creation)
nameStringYesDisplay name of the collection
descriptionStringNoRich text description of the collection
slugStringYesURL-friendly identifier for the collection
collectionBGImageStringNoBackground image filename
positionIntegerNoOrder position for display
expireDateDateNoDate when the collection expires
publishedDateDateNoDate when the collection is published
collectionTypeStringNoType of collection (default: "default")
sortPreferenceStringNoHow content should be sorted (e.g., "most recent first")
PlatformIdIntegerYesID of the platform this collection belongs to
UserIdIntegerNoID of the user creating this collection
showOnHomepageBooleanNoWhether to show on homepage
GroupIdsArrayNoArray of group IDs to associate with this collection
ContentIdsArrayNoArray 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 PlatformId must match the user's platform.
  • If GroupIds is provided, the collection will be associated with those groups.
  • If ContentIds is 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 ContentIds array.

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]
}'