Skip to content

answers.get()

Retrieves a single answer by its ID with complete answer details and metadata.

async get(questionId: number, answerId: number): Promise<AnswerResponseModel>
ParameterTypeRequiredDescription
questionIdnumberYesThe unique identifier of the question that contains the answer
answerIdnumberYesThe unique identifier of the answer to retrieve

Returns a Promise<AnswerResponseModel> containing the complete answer object with the following properties:

PropertyTypeDescription
idnumberThe answer’s unique identifier
questionIdnumberThe ID of the answered question
bodystringThe main content of the answer in HTML format
bodyMarkdownstringThe main content of the answer in Markdown format
scorenumberAnswer score (upvotes minus downvotes)
isAcceptedbooleanWhether this is the accepted answer for the question
isDeletedbooleanWhether the answer was deleted
isBookmarkedbooleanWhether the logged-in user bookmarked the answer
isFollowedbooleanWhether the logged-in user followed the answer
creationDateDateWhen the answer was created
lastEditDateDate | nullWhen the answer was last edited
lastActivityDateDate | nullWhen the answer last had activity
lockedDateDate | nullWhen the answer was locked
deletionDateDate | nullWhen the answer was deleted
ownerUserSummaryResponseModelInformation about the answer author
lastEditorUserSummaryResponseModelInformation about who last edited the answer
lastActivityUserUserSummaryResponseModelInformation about who performed the last activity
commentCountnumberNumber of comments on the answer
webUrlstring | nullDirect URL to the answer
shareLinkstring | nullLink for sharing the answer
userCanFollowbooleanWhether the logged-in user can follow the answer
canBeFollowedbooleanWhether anyone can follow the answer
isSubjectMatterExpertbooleanWhether the answer is from a subject matter expert
import { StackOverflowSDK } from 'so-teams-sdk';
const sdk = new StackOverflowSDK({
accessToken: 'your-access-token',
baseUrl: 'https://[your-site].stackenterprise.co/api/v3'
});
// Get a specific answer
const answer = await sdk.answers.get(123, 456);
console.log(answer.body);
console.log(`Score: ${answer.score}`);
console.log(`Accepted: ${answer.isAccepted}`);
const answer = await sdk.answers.get(123, 456);
// Check answer metadata
if (answer.isAccepted) {
console.log('This is the accepted answer!');
}
// Get author information
console.log(`Answer by: ${answer.owner?.displayName}`);
// Access both HTML and Markdown content
console.log('HTML content:', answer.body);
console.log('Markdown content:', answer.bodyMarkdown);
// Check edit history
if (answer.lastEditDate) {
console.log(`Last edited: ${answer.lastEditDate}`);
console.log(`Edited by: ${answer.lastEditor?.displayName}`);
}
// Using team context
const teamSDK = sdk.forTeam('team-123');
const teamAnswer = await teamSDK.answers.get(123, 456);
// Or with direct client initialization
import { AnswerClient } from 'so-teams-sdk';
const teamAnswerClient = new AnswerClient(config, 'team-123');
const answer = await teamAnswerClient.get(123, 456);

This method can throw the following errors:

Error TypeStatus CodeDescription
AuthenticationError401Invalid or missing authentication token
TokenExpiredError401Authentication token has expired
ForbiddenError403Insufficient permissions to access the answer
NotFoundError404Question or answer with the specified ID does not exist
SDKErrorVariousOther API or network errors
import StackOverflowSDK, { NotFoundError, ForbiddenError } from 'so-teams-sdk';
const sdk = new StackOverflowSDK({
accessToken: 'your-access-token',
baseUrl: 'https://[your-site].stackenterprise.co/api/v3'
});
try {
const answer = await sdk.answers.get(123, 456);
console.log('Answer retrieved:', answer.body);
} catch (error) {
if (error instanceof NotFoundError) {
console.error('Answer or question not found');
} else if (error instanceof ForbiddenError) {
console.error('Access denied to this answer');
} else {
console.error('Failed to retrieve answer:', error.message);
}
}
  • This method returns the complete answer object with all available fields, unlike getAll() which returns summary objects
  • Both HTML and Markdown versions of the content are available in the response
  • User-specific fields like isBookmarked and isFollowed reflect the state for the authenticated user
  • Deleted answers may still be retrievable depending on permissions, but will have isDeleted: true