Skip to content

answers.removeDownvote()

Removes a previously cast downvote from an answer, returning the vote count to its previous state.

async removeDownvote(questionId: number, answerId: number): Promise<AnswerSummaryResponseModel>
ParameterTypeRequiredDescription
questionIdnumberYesThe unique identifier of the question that contains the answer
answerIdnumberYesThe unique identifier of the answer to remove the downvote from

Returns a Promise<AnswerSummaryResponseModel> containing updated answer summary information with the adjusted vote count and score.

import { StackOverflowSDK } from 'so-teams-sdk';
const sdk = new StackOverflowSDK({
accessToken: 'your-access-token',
baseUrl: 'https://[your-site].stackenterprise.co/api/v3'
});
// Remove a downvote from an answer
const result = await sdk.answers.removeDownvote(123, 456);
console.log(`Answer score is now: ${result.score}`);
try {
const answerBefore = await sdk.answers.get(123, 456);
console.log(`Current score: ${answerBefore.score}`);
const result = await sdk.answers.removeDownvote(123, 456);
console.log(`Score after removing downvote: ${result.score}`);
console.log(`Score increased by: ${result.score - answerBefore.score}`);
} catch (error) {
console.error('Failed to remove downvote:', error.message);
}
async function removeDownvoteIfExists(questionId: number, answerId: number) {
try {
const result = await sdk.answers.removeDownvote(questionId, answerId);
console.log(`Removed downvote from answer ${answerId}, new score: ${result.score}`);
return { removed: true, score: result.score };
} catch (error) {
if (error.message.includes('no downvote') || error.message.includes('not voted')) {
console.log('No downvote to remove');
return { removed: false, reason: 'no_downvote' };
} else {
console.error('Error removing downvote:', error.message);
throw error;
}
}
}
const result = await removeDownvoteIfExists(123, 456);
async function changeVoteToUpvote(questionId: number, answerId: number) {
try {
// First, remove existing downvote
await sdk.answers.removeDownvote(questionId, answerId);
console.log('Downvote removed');
// Then cast an upvote
const result = await sdk.answers.upvote(questionId, answerId);
console.log(`Changed vote to upvote, new score: ${result.score}`);
return result;
} catch (error) {
console.error('Failed to change vote:', error.message);
throw error;
}
}
await changeVoteToUpvote(123, 456);
// Using team context
const teamSDK = sdk.forTeam('team-123');
const result = await teamSDK.answers.removeDownvote(123, 456);
// Or with direct client initialization
import { AnswerClient } from 'so-teams-sdk';
const teamAnswerClient = new AnswerClient(config, 'team-123');
const voteResult = await teamAnswerClient.removeDownvote(123, 456);
async function removeDownvotesFromMultipleAnswers(questionId: number, answerIds: number[]) {
const results = [];
for (const answerId of answerIds) {
try {
const result = await sdk.answers.removeDownvote(questionId, answerId);
results.push({
answerId,
status: 'removed',
newScore: result.score
});
console.log(`Removed downvote from answer ${answerId}`);
} catch (error) {
results.push({
answerId,
status: 'failed',
error: error.message
});
console.error(`Failed to remove downvote from answer ${answerId}:`, error.message);
}
}
return results;
}
const results = await removeDownvotesFromMultipleAnswers(123, [456, 789]);
console.log('Vote removal results:', results);

This method can throw the following errors:

Error TypeStatus CodeDescription
AuthenticationError401Invalid or missing authentication token
TokenExpiredError401Authentication token has expired
ForbiddenError403Cannot remove downvote (no existing downvote, insufficient permissions)
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 result = await sdk.answers.removeDownvote(123, 456);
console.log('Downvote removed successfully, new score:', result.score);
} catch (error) {
if (error instanceof NotFoundError) {
console.error('Answer not found');
} else if (error instanceof ForbiddenError) {
if (error.message.includes('no downvote') || error.message.includes('not voted')) {
console.error('You have not downvoted this answer');
} else {
console.error('Cannot remove downvote:', error.message);
}
} else {
console.error('Failed to remove downvote:', error.message);
}
}
async function safeRemoveDownvote(questionId: number, answerId: number) {
try {
const result = await sdk.answers.removeDownvote(questionId, answerId);
return {
success: true,
score: result.score,
message: 'Downvote removed successfully'
};
} catch (error) {
if (error instanceof ForbiddenError) {
if (error.message.includes('no downvote') || error.message.includes('not voted')) {
return {
success: false,
reason: 'no_downvote',
message: 'No downvote exists to remove'
};
}
}
return {
success: false,
reason: 'error',
message: error.message
};
}
}
const result = await safeRemoveDownvote(123, 456);
if (result.success) {
console.log('Downvote removed, new score:', result.score);
} else {
console.log('Could not remove downvote:', result.message);
}
  • This method can only be called if the user has previously downvoted the answer
  • Calling this method when no downvote exists will result in a ForbiddenError
  • After removing a downvote, the user can cast either an upvote or downvote on the same answer
  • The score increase depends on the voting system (typically increases by 1)
  • Vote removal is immediate and reflected in the returned response
  • Users cannot remove votes on their own answers (since they can’t vote on them in the first place)
  • Some platforms may have time limits on vote changes - after a certain period, votes may become locked
  • The returned AnswerSummaryResponseModel contains the updated vote-related information
  • Removing a downvote may restore any reputation penalties that were applied to the voter