Skip to content

articles.getAll()

Retrieves a paginated list of articles with comprehensive filtering, sorting, and date range options.

async getAll(options?: GetArticlesOptions): Promise<PaginatedArticles>
ParameterTypeRequiredDescription
optionsGetArticlesOptionsNoConfiguration options for pagination, filtering, and sorting
PropertyTypeRequiredDefaultDescription
pagenumberNo1The page number to retrieve (1-based)
pageSize15 | 30 | 50 | 100No30Number of articles to return per page
sortArticleSortParameterNoSort articles by: "activity", "creation", or "score"
orderSortOrderNoSort order: "asc" (ascending) or "desc" (descending)
tagIdnumber[]NoFilter articles by specific tag IDs
authorIdnumberNoFilter articles by specific author ID
fromDateNoFilter articles created after this date
toDateNoFilter articles created before this date

Returns a Promise<PaginatedArticles> containing:

PropertyTypeDescription
totalCountnumberTotal number of articles matching the criteria
pageSizenumberNumber of items per page
pagenumberCurrent page number
totalPagesnumberTotal number of pages available
sortArticleSortParameterSort parameter used
orderSortOrderSort order used
itemsArticleResponseModel[]Array of article 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 articles with default settings
const articles = await sdk.articles.getAll();
console.log(`Found ${articles.totalCount} articles`);
// Get the second page with 50 articles per page
const articles = await sdk.articles.getAll({
page: 2,
pageSize: 50
});
console.log(`Page ${articles.page} of ${articles.totalPages}`);
// Get newest articles first
const newestArticles = await sdk.articles.getAll({
sort: 'creation',
order: 'desc',
pageSize: 15
});
// Get highest-scored articles
const topArticles = await sdk.articles.getAll({
sort: 'score',
order: 'desc'
});
// Get articles by a specific author
const authorArticles = await sdk.articles.getAll({
authorId: 123,
sort: 'creation',
order: 'desc'
});
console.log(`Author has ${authorArticles.totalCount} articles`);
// Get articles with specific tags
const taggedArticles = await sdk.articles.getAll({
tagId: [456, 789], // Articles with tag ID 456 OR 789
pageSize: 30
});
// Get articles with single tag
const singleTagArticles = await sdk.articles.getAll({
tagId: [123]
});
// Get articles from the last month
const lastMonth = new Date();
lastMonth.setMonth(lastMonth.getMonth() - 1);
const recentArticles = await sdk.articles.getAll({
from: lastMonth,
to: new Date(),
sort: 'creation',
order: 'desc'
});
// Get articles from a specific date range
const articles2024 = await sdk.articles.getAll({
from: new Date('2024-01-01'),
to: new Date('2024-12-31')
});
// Complex filtering: articles by specific author, with certain tags, from last quarter
const quarterStart = new Date();
quarterStart.setMonth(quarterStart.getMonth() - 3);
const filteredArticles = await sdk.articles.getAll({
authorId: 123,
tagId: [456, 789],
from: quarterStart,
sort: 'score',
order: 'desc',
pageSize: 25
});
console.log(`Found ${filteredArticles.totalCount} articles matching all criteria`);
// Using team context
const teamSDK = sdk.forTeam('team-123');
const teamArticles = await teamSDK.articles.getAll({
sort: 'creation',
order: 'desc'
});
// Or with direct client initialization
import { ArticleClient } from 'so-teams-sdk';
const teamArticleClient = new ArticleClient(config, 'team-123');
const articles = await teamArticleClient.getAll();
async function getAllArticlesByAuthor(authorId: number): Promise<ArticleResponseModel[]> {
const allArticles: ArticleResponseModel[] = [];
let currentPage = 1;
let hasMorePages = true;
while (hasMorePages) {
const result = await sdk.articles.getAll({
authorId,
page: currentPage,
pageSize: 100, // Maximum page size for efficiency
sort: 'creation',
order: 'desc'
});
allArticles.push(...result.items);
hasMorePages = currentPage < result.totalPages;
currentPage++;
console.log(`Loaded page ${currentPage - 1} of ${result.totalPages}`);
}
return allArticles;
}
const authorArticles = await getAllArticlesByAuthor(123);
console.log(`Total articles loaded: ${authorArticles.length}`);

This method can throw the following errors:

Error TypeStatus CodeDescription
AuthenticationError401Invalid or missing authentication token
TokenExpiredError401Authentication token has expired
ForbiddenError403Insufficient permissions to access articles
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 articles = await sdk.articles.getAll({
authorId: 123,
pageSize: 50
});
console.log(`Successfully retrieved ${articles.items.length} articles`);
articles.items.forEach(article => {
console.log(`- ${article.title} (Score: ${article.score})`);
});
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Authentication required to access articles');
} else if (error instanceof ForbiddenError) {
console.error('Access denied to articles');
} else {
console.error('Failed to retrieve articles:', error.message);
}
}
  • All filter parameters are optional and can be combined for precise filtering
  • The tagId parameter accepts an array of tag IDs - articles matching ANY of the specified tags will be returned
  • Date filtering uses the article’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
  • Large date ranges may return many results - consider using pagination for better performance
  • Tag and author filtering can significantly improve query performance compared to client-side filtering