Skip to content

collections.getAll()

Retrieves a paginated list of collections with comprehensive filtering, sorting, and permission-based access control.

async getAll(options?: GetCollectionsOptions): Promise<PaginatedCollections>
ParameterTypeRequiredDescription
optionsGetCollectionsOptionsNoConfiguration options for pagination, filtering, and sorting
PropertyTypeRequiredDefaultDescription
pagenumberNo1The page number to retrieve (1-based)
pageSize15 | 30 | 50 | 100No30Number of collections to return per page
sortCollectionsSortParameterNoSort collections by: "creation" or "lastEdit"
orderSortOrderNoSort order: "asc" (ascending) or "desc" (descending)
authorIdsnumber[]NoFilter collections by specific author/owner IDs
partialTitlestringNoFilter collections by partial title match (search)
permissionsCollectionsPermissionsFilterNoFilter by permission level: "all", "owned", or "editable"
fromDateNoFilter collections created after this date
toDateNoFilter collections created before this date

Returns a Promise<PaginatedCollections> containing:

PropertyTypeDescription
totalCountnumberTotal number of collections matching the criteria
pageSizenumberNumber of items per page
pagenumberCurrent page number
totalPagesnumberTotal number of pages available
sortCollectionsSortParameterSort parameter used
orderSortOrderSort order used
itemsCollectionsResponseModel[]Array of collection objects
import { StackOverflowSDK } from 'so-teams-sdk';
const sdk = new StackOverflowSDK({
accessToken: 'your-access-token',
baseUrl: 'https://[your-site].stackenterprise.co/api/v3'
});
// Get all collections with default settings
const collections = await sdk.collections.getAll();
console.log(`Found ${collections.totalCount} collections`);
// Display collections
collections.items.forEach(collection => {
console.log(`- ${collection.title} (${collection.content?.length || 0} items)`);
});
// Get the second page with 50 collections per page
const collections = await sdk.collections.getAll({
page: 2,
pageSize: 50
});
console.log(`Page ${collections.page} of ${collections.totalPages}`);
console.log(`Showing ${collections.items.length} of ${collections.totalCount} collections`);
// Get newest collections first
const newestCollections = await sdk.collections.getAll({
sort: 'creation',
order: 'desc',
pageSize: 15
});
// Get recently modified collections
const recentlyModified = await sdk.collections.getAll({
sort: 'lastEdit',
order: 'desc'
});
// Get collections by a specific author
const authorCollections = await sdk.collections.getAll({
authorIds: [123],
sort: 'creation',
order: 'desc'
});
// Get collections by multiple authors
const multiAuthorCollections = await sdk.collections.getAll({
authorIds: [123, 456, 789],
pageSize: 25
});
console.log(`Found ${authorCollections.totalCount} collections by this author`);
// Search collections by partial title
const searchResults = await sdk.collections.getAll({
partialTitle: 'typescript',
sort: 'creation',
order: 'desc'
});
// Search with additional filters
const filteredSearch = await sdk.collections.getAll({
partialTitle: 'guide',
authorIds: [123],
permissions: 'editable'
});
console.log(`Found ${searchResults.totalCount} collections matching "typescript"`);
// Get only collections I own
const ownedCollections = await sdk.collections.getAll({
permissions: 'owned',
sort: 'lastEdit',
order: 'desc'
});
// Get collections I can edit
const editableCollections = await sdk.collections.getAll({
permissions: 'editable',
pageSize: 50
});
// Get all accessible collections
const allCollections = await sdk.collections.getAll({
permissions: 'all'
});
console.log(`Owned: ${ownedCollections.totalCount}, Editable: ${editableCollections.totalCount}, All: ${allCollections.totalCount}`);
// Get collections from the last month
const lastMonth = new Date();
lastMonth.setMonth(lastMonth.getMonth() - 1);
const recentCollections = await sdk.collections.getAll({
from: lastMonth,
sort: 'creation',
order: 'desc'
});
// Get collections from a specific period
const periodCollections = await sdk.collections.getAll({
from: new Date('2024-01-01'),
to: new Date('2024-12-31'),
sort: 'creation',
order: 'desc'
});
console.log(`${recentCollections.totalCount} collections created in the last month`);
// Using team context
const teamSDK = sdk.forTeam('team-123');
const teamCollections = await teamSDK.collections.getAll({
sort: 'creation',
order: 'desc'
});
// Or with direct client initialization
import { CollectionClient } from 'so-teams-sdk';
const teamCollectionClient = new CollectionClient(config, 'team-123');
const collections = await teamCollectionClient.getAll();
// Advanced search with multiple filters
const advancedSearch = await sdk.collections.getAll({
partialTitle: 'best practices',
authorIds: [123, 456],
permissions: 'editable',
sort: 'lastEdit',
order: 'desc',
pageSize: 25
});
// Date range with author and search
const quarterStart = new Date();
quarterStart.setMonth(quarterStart.getMonth() - 3);
const quarterlyCollections = await sdk.collections.getAll({
from: quarterStart,
authorIds: [123],
partialTitle: 'tutorial',
sort: 'creation',
order: 'desc'
});
console.log(`Found ${advancedSearch.totalCount} matching collections`);
async function analyzeCollections() {
try {
// Get all collections for analysis
const allCollections = await sdk.collections.getAll({
pageSize: 100,
sort: 'creation',
order: 'desc'
});
// Analyze collection metrics
const analytics = {
total: allCollections.totalCount,
averageContentItems: allCollections.items.reduce((sum, c) => sum + (c.content?.length || 0), 0) / allCollections.items.length,
collectionsWithContent: allCollections.items.filter(c => (c.content?.length || 0) > 0).length,
emptyCollections: allCollections.items.filter(c => (c.content?.length || 0) === 0).length,
deletedCollections: allCollections.items.filter(c => c.isDeleted).length,
uniqueOwners: new Set(allCollections.items.map(c => c.owner?.id).filter(Boolean)).size,
collectionsWithEditors: allCollections.items.filter(c =>
(c.editorUsers?.length || 0) > 0 || (c.editorUserGroups?.length || 0) > 0
).length
};
// Analyze tags
const allTags = allCollections.items.flatMap(c => c.tags || []);
const tagFrequency = allTags.reduce((freq, tag) => {
const tagName = tag.name || 'unknown';
freq[tagName] = (freq[tagName] || 0) + 1;
return freq;
}, {} as Record<string, number>);
const topTags = Object.entries(tagFrequency)
.sort(([,a], [,b]) => b - a)
.slice(0, 10)
.map(([tag, count]) => ({ tag, count }));
// Analyze creation patterns
const creationDates = allCollections.items.map(c => new Date(c.creationDate));
const oldestCollection = new Date(Math.min(...creationDates.map(d => d.getTime())));
const newestCollection = new Date(Math.max(...creationDates.map(d => d.getTime())));
const result = {
metrics: analytics,
topTags,
dateRange: {
oldest: oldestCollection,
newest: newestCollection,
timespan: `${Math.ceil((newestCollection.getTime() - oldestCollection.getTime()) / (1000 * 60 * 60 * 24))} days`
}
};
console.log('Collection Analytics:', result);
return result;
} catch (error) {
console.error('Failed to analyze collections:', error.message);
throw error;
}
}
const analytics = await analyzeCollections();
async function getAllCollectionsByAuthor(authorId: number): Promise<CollectionsResponseModel[]> {
const allCollections: CollectionsResponseModel[] = [];
let currentPage = 1;
let hasMorePages = true;
while (hasMorePages) {
const result = await sdk.collections.getAll({
authorIds: [authorId],
page: currentPage,
pageSize: 100, // Maximum page size for efficiency
sort: 'creation',
order: 'desc'
});
allCollections.push(...result.items);
hasMorePages = currentPage < result.totalPages;
currentPage++;
console.log(`Loaded page ${currentPage - 1} of ${result.totalPages}`);
}
return allCollections;
}
const authorCollections = await getAllCollectionsByAuthor(123);
console.log(`Total collections loaded: ${authorCollections.length}`);

This method can throw the following errors:

Error TypeStatus CodeDescription
AuthenticationError401Invalid or missing authentication token
TokenExpiredError401Authentication token has expired
ForbiddenError403Insufficient permissions to access collections
SDKErrorVariousOther API or network errors
import StackOverflowSDK, { AuthenticationError, ForbiddenError } from 'so-teams-sdk';
const sdk = new StackOverflowSDK({
accessToken: 'your-access-token',
baseUrl: 'https://[your-site].stackenterprise.co/api/v3'
});
try {
const collections = await sdk.collections.getAll({
permissions: 'editable',
pageSize: 50
});
console.log(`Successfully retrieved ${collections.items.length} collections`);
collections.items.forEach(collection => {
console.log(`- ${collection.title} (Content: ${collection.content?.length || 0} items)`);
});
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Authentication required to access collections');
} else if (error instanceof ForbiddenError) {
console.error('Access denied to collections');
} else {
console.error('Failed to retrieve collections:', error.message);
}
}
  • All filter parameters are optional and can be combined for precise filtering
  • The partialTitle parameter performs case-insensitive substring matching
  • Permission filtering (owned, editable, all) respects the user’s access rights
  • Date filtering uses the collection’s creation date
  • When no sorting options are provided, the API uses its default sorting behavior
  • Page numbers are 1-based (first page is page: 1)
  • Empty results are returned as an array with totalCount: 0 rather than throwing an error
  • Collections include metadata about their content, editors, and associated tags
  • The permissions filter is particularly useful for building user-specific collection views