stack-exchange
The stack-exchange is a simple npm module that provides a wrapper to access StackOverflow API endpoint.
Installation
Installation is done using the npm install command:
$ npm install stack-exchange
Quick Start
You can make 300 requests without a key per day, with a key you can make 10,000 requests. To generate key visit here.The sections are as follows
For more details about the endpoints on each section visit table-of-content. To use above mentioned sections endpoints, you need to create their respective sections objects as follows:
const stackexchange = require("stack-exchange")({ version : "2.2" });
const stack_users = stackexchange.users;
const stack_me = stackexchange.me;
const stack_questions = stackexchange.questions;
const stack_answers = stackexchange.answers;
const stack_badges = stackexchange.badges;
const stack_tags = stackexchange.tags;
const stack_comments = stackexchange.comments;
const stack_posts = stackexchange.posts;
const stack_search = stackexchange.search;
const stack_suggested_edits = stackexchange.suggested_edits;
const stack_network = stackexchange.network;
const stack_info = stackexchange.info;
const stack_privilages = stackexchange.privilages;
const stack_revisions = stackexchange.revisions;
const stack_events = stackexchange.events;
users section
All user methods that take an {ids} parameter have a /me equivalent method that takes an access_token instead.
const stack_users = stackexchange.users;
users
Get all users on the site.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_users.users(users_options, (response) => {
console.log(response);
});
users_by_ids
Get the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.users_by_ids(user_ids, users_options, (response) => {
console.log(response);
});
answers_on_users
Get the answers posted by the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.answers_on_users(user_ids, users_options, (response) => {
console.log(response);
});
badges_on_users
Get the badges earned by the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.badges_on_users(user_ids, users_options, (response) => {
console.log(response);
});
Get the comments posted by the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.comments_on_users(user_ids, users_options, (response) => {
console.log(response);
});
Get the comments posted by a set of users in reply to another user.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
let toid = 1427878;
stack_users.comments_by_users_to_user(user_ids, toid , users_options, (response) => {
console.log(response);
});
favorites_on_users
Get the questions favorited by users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.favorites_on_users(user_ids, users_options, (response) => {
console.log(response);
});
mentions_on_users
Get the comments that mention one of the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.mentions_on_users(user_ids, users_options, (response) => {
console.log(response);
});
users_network_activity
Gets a user's activity across the Stack Exchange network.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.users_network_activity(user_ids, users_options, (response) => {
console.log(response);
});
user_notifications
Get a user's notifications.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.user_notifications(user_ids, users_options, (response) => {
console.log(response);
});
user_unread_notifications
Get a user's unread notifications.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.user_unread_notifications(user_ids, users_options, (response) => {
console.log(response);
});
posts_on_users
Get all posts (questions and answers) owned by a set of users.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.posts_on_users(user_ids, users_options, (response) => {
console.log(response);
});
privileges_on_users
Get the privileges the given user has on the site.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.privileges_on_users(user_ids, users_options, (response) => {
console.log(response);
});
questions_on_users
Get the questions asked by the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.questions_on_users(user_ids, users_options, (response) => {
console.log(response);
});
featured_questions_on_users
Get the questions on which a set of users, have active bounties.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.featured_questions_on_users(user_ids, users_options, (response) => {
console.log(response);
});
no_answer_questions_on_users
Get the questions asked by a set of users, which have no answers.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.no_answer_questions_on_users(user_ids, users_options, (response) => {
console.log(response);
});
unaccepted_questions_on_users
Get the questions asked by a set of users, which have at least one answer but no accepted answer.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.unaccepted_questions_on_users(user_ids, users_options, (response) => {
console.log(response);
});
unanswered_questions_on_users
Get the questions asked by a set of users, which are not considered to be adequately answered.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.unanswered_questions_on_users(user_ids, users_options, (response) => {
console.log(response);
});
reputation_on_users
Get a subset of the reputation changes experienced by the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.reputation_on_users(user_ids, users_options, (response) => {
console.log(response);
});
reputation_history
Get a history of a user's reputation, excluding private events.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.reputation_history(user_ids, users_options, (response) => {
console.log(response);
});
full_reputation_history
Get a full history of a user's reputation. auth required
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.full_reputation_history(user_ids, users_options, (response) => {
console.log(response);
});
tags_on_users
Get the tags that the users (identified by a set of ids) have been active in.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.tags_on_users(user_ids, users_options, (response) => {
console.log(response);
});
suggested_edits_on_users
Get the suggested edits provided by users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.suggested_edits_on_users(user_ids, users_options, (response) => {
console.log(response);
});
top_user_answers_in_tags
Get the top answers a user has posted on questions with a set of tags.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
let tags = "nodejs";
stack_users.top_user_answers_in_tags(user_ids, tags, users_options, (response) => {
console.log(response);
});
top_user_questions_in_tags
Get the top questions a user has posted with a set of tags.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
let tags = "nodejs";
stack_users.top_user_questions_in_tags(user_ids, tags, users_options, (response) => {
console.log(response);
});
timeline_on_users
Get a subset of the actions of that have been taken by the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.timeline_on_users(user_ids, users_options, (response) => {
console.log(response);
});
top_answer_tags_on_users
Get the top tags (by score) a single user has posted answers in.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.top_answer_tags_on_users(user_ids, users_options, (response) => {
console.log(response);
});
top_tags_on_users
Get the top tags (by score) a single user has posted in.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.top_tags_on_users(user_ids, users_options, (response) => {
console.log(response);
});
top_question_tags_on_users
Get the top tags (by score) a single user has asked questions in.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.top_question_tags_on_users(user_ids, users_options, (response) => {
console.log(response);
});
moderators
Get the users who have moderation powers on the site.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_users.moderators(users_options, (response) => {
console.log(response);
});
elected_moderators
Get the users who are active moderators who have also won a moderator election.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_users.elected_moderators(users_options, (response) => {
console.log(response);
});
user_inbox
Get a user's inbox. auth required
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.user_inbox(user_ids, users_options, (response) => {
console.log(response);
});
user_unread_inbox
Get the unread items in a user's inbox. auth required
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.user_unread_inbox(user_ids, users_options, (response) => {
console.log(response);
});
associated_users
Get a user's associated accounts.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.associated_users(user_ids, users_options, (response) => {
console.log(response);
});
merge_history
Get the merges a user's accounts has undergone.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let user_ids = "6414102";
stack_users.merge_history(user_ids, users_options, (response) => {
console.log(response);
});
me section
/me are users equivalent methods that takes an access_token instead. These methods are provided for developer convenience, with the exception of plain /me, which is actually necessary for discovering which user authenticated to an application.
const stack_me = stackexchange.me;
me
Get the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me( users_options, (response) => {
console.log(response);
});
me_answers
Get the answers posted by the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_answers( users_options, (response) => {
console.log(response);
});
me_badges
Get the badges earned by the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_badges( users_options, (response) => {
console.log(response);
});
Get the comments posted by the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_comments( users_options, (response) => {
console.log(response);
});
Get the comments posted by a set of users in reply to another user.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let toid = 1427878;
stack_me.me_comments_to(toid, users_options, (response) => {
console.log(response);
});
me_favorites
Get the questions favorited by users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_favorites(users_options, (response) => {
console.log(response);
});
me_mentioned
Get the comments that mention one of the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_mentioned(users_options, (response) => {
console.log(response);
});
me_network_activity
Gets a user's activity across the Stack Exchange network.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_network_activity(users_options, (response) => {
console.log(response);
});
me_notifications
Get a user's notifications.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_notifications(users_options, (response) => {
console.log(response);
});
me_unread_notifications
Get a user's unread notifications.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_unread_notifications(users_options, (response) => {
console.log(response);
});
me_posts
Get all posts (questions and answers) owned by a set of users.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_posts(users_options, (response) => {
console.log(response);
});
me_privileges
Get the privileges the given user has on the site.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_privileges(users_options, (response) => {
console.log(response);
});
me_questions
Get the questions asked by the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_questions(users_options, (response) => {
console.log(response);
});
me_featured_questions
Get the questions on which a set of users, have active bounties.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_featured_questions(users_options, (response) => {
console.log(response);
});
me_no_answer_questions
Get the questions asked by a set of users, which have no answers.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_no_answer_questions(users_options, (response) => {
console.log(response);
});
me_unaccepted_questions
Get the questions asked by a set of users, which have at least one answer but no accepted answer.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_unaccepted_questions(users_options, (response) => {
console.log(response);
});
me_unanswered_questions
Get the questions asked by a set of users, which are not considered to be adequately answered.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_unanswered_questions(users_options, (response) => {
console.log(response);
});
me_reputation
Get a subset of the reputation changes experienced by the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_reputation(users_options, (response) => {
console.log(response);
});
me_reputation_history
Get a history of a user's reputation, excluding private events.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_reputation_history(users_options, (response) => {
console.log(response);
});
me_full_reputation_history
Get a full history of a user's reputation. auth required
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_full_reputation_history(users_options, (response) => {
console.log(response);
});
me_suggested_edits
Get the suggested edits provided by users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_suggested_edits(users_options, (response) => {
console.log(response);
});
me_tags
Get the tags that the users (identified by a set of ids) have been active in.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_tags(users_options, (response) => {
console.log(response);
});
me_tags_top_questions
Get the top questions a user has posted with a set of tags.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let tags = "nodejs";
stack_me.me_tags_top_questions(tags, users_options, (response) => {
console.log(response);
});
me_tags_top_answers
Get the top answers a user has posted on questions with a set of tags.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
let tags = "nodejs";
stack_me.me_tags_top_answers(tags, users_options, (response) => {
console.log(response);
});
me_top_answer_tags
Get the top tags (by score) a single user has posted answers in.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_top_answer_tags( users_options, (response) => {
console.log(response);
});
me_top_question_tags
Get the top tags (by score) a single user has asked questions in.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_top_question_tags( users_options, (response) => {
console.log(response);
});
me_timeline
Get a subset of the actions of that have been taken by the users identified by a set of ids.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_timeline(users_options, (response) => {
console.log(response);
});
me_top_tags
Get the top tags (by score) a single user has posted in.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_top_tags( users_options, (response) => {
console.log(response);
});
me_inbox
Get a user's inbox. auth required
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_inbox( users_options, (response) => {
console.log(response);
});
me_unread_inbox
Get the unread items in a user's inbox. auth required
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_unread_inbox( users_options, (response) => {
console.log(response);
});
me_associated_users
Get a user's associated accounts.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_associated_users(users_options, (response) => {
console.log(response);
});
me_merge_history
Get the merges a user's accounts has undergone.
let users_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_me.me_merge_history(inbox_options, (response) => {
console.log(response);
});
questions section
The options object is optional, can be an empty object also. update all your query fields in it. supported query fields are as follows:
let options = {
"order": "desc",
"sort": "activity",
"site": "stackoverflow",
"key" : "your_key"
}
const stack_questions = stackexchange.questions;
questions
Get all questions on the site.
stack_questions.questions(options , (response) => {
console.log(response);
});
questions by ids
Get the questions identified by a set of ids.
ids = "47559184"
stack_questions.questions_by_ids(ids , options , (response) => {
console.log(response);
});
answers on questions
Get the answers to the questions identified by a set of ids.
id = "47596027"
stack_questions.answers_on_questions(id, options , (response) => {
console.log(response);
});
render answers
Renders a hypothetical answer to a question. This is a post endpoints, the options section looks like this, both fields are required.
let options = {
"body": "hello",
"site": "stackoverflow"
}
let id = "47596027"
stack_questions.render_answer(id, options , (response) => {
console.log(response);
});
linked questions
Get the questions that link to the questions identified by a set of ids.
let id = "1884724";
stack_questions.linked_questions(id, options , (response) => {
console.log(response);
});
related questions
Get the questions that are related to the questions identified by a set of ids.
let id = "37878662";
stack_questions.related_questions(id, options , (response) => {
console.log(response);
});
questions timeline
Get the timelines of the questions identified by a set of ids.
let id = "37878662";
stack_questions.questions_timeline(id, options, (response) => {
console.log(response);
});
featured questions
Get all questions on the site with active bounties.
stack_questions.featured_questions(options, (response) => {
console.log(response);
});
no answer questions
Get all questions on the site with no answers.
stack_questions.no_answer_questions( options , (response) => {
console.log(response);
});
unanswered questions
Get all questions the site considers unanswered.
stack_questions.unanswered_questions( options , (response) => {
console.log(response);
});
unanswered questions my tags
Get questions the site considers unanswered within a user's favorite or interesting tags. auth required This endpoint required access_token and key in options.
stack_questions.unanswered_questions_my_tags( options , (response) => {
console.log(response);
});
question flag options
Returns valid flag options for the given question. auth required. This endpoint required access_token and key in options.
let options = {
"key": "your_key",
"access_token": "your_token",
"site": "stackoverflow"
}
let question_id = "37878662";
stack_questions.question_flag_options(question_id, options, (response) => {
console.log(response);
});
question close options
Returns valid flag options which are also close reasons for the given question. auth required. This endpoint required access_token and key in options.
let options = {
"key": "your_key",
"access_token": "your_token",
"site": "stackoverflow"
}
let question_id = "37878662";
stack_questions.question_close_options(question_id, options, (response) => {
console.log(response);
});
Get the comments on the questions identified by a set of ids. This endpoint required access_token and key in options.
let options = {
"key": "your_key",
"access_token": "your_token",
"site": "stackoverflow"
}
let question_id = "45934757";
stack_questions.comments_on_questions(question_id, options, (response) => {
console.log(response);
});
answers section
The options object is optional, can be an empty object also. update all your query fields in it.
const stack_answers = stackexchange.answers;
answers
Get all answers on the site.
let options = {
"key": "your_key",
"access_token": "your_token"
}
stack_answers.answers(answers_options, (response) => {
console.log(response);
});
answers_by_ids
Get answers identified by a set of ids.
let options = {
"key": "your_key",
"access_token": "your_token"
}
let answer_id = "6414102";
stack_answers.answers_by_ids(answer_id, answers_options, (response) => {
console.log(response);
});
accept_answer
Casts an accept vote on the given answer. auth required
let options = {
"key": "your_key",
"access_token": "your_token"
}
let answer_id = "6414102";
stack_answers.accept_answer(answer_id, answers_options, (response) => {
console.log(response);
});
undo_accept_answer
Undoes an accept vote on the given answer. auth required
let options = {
"key": "your_key",
"access_token": "your_token"
}
let answer_id = "47451356";
stack_answers.undo_accept_answer(answer_id, answers_options, (response) => {
console.log(response);
});
Get comments on the answers identified by a set of ids.
let options = {
"key": "your_key",
"access_token": "your_token"
}
let answer_id = "37886434";
stack_answers.comments_on_answers(answer_id, answers_options, (response) => {
console.log(response);
});
badges section
let badges_options = {
"site": "stackoverflow",
"key": "U4DMV*8nvpm3EOpvf69Rxw(("
}
const stack_badges = stackexchange.badges;
badges
Get all badges on the site, in alphabetical order.
stack_badges.badges(badges_options, (response) => {
console.log(response);
});
badges_by_id
Get the badges identified by ids.
let id = "222"
stack_badges.badges_by_id(id, badges_options, (response) => {
console.log(response);
});
badges_by_name
Get all non-tagged-based badges in alphabetical order.
let name = "fanatic"
stack_badges.badges_by_name(name, badges_options, (response) => {
console.log(response);
});
badge_recipients
Get badges recently awarded on the site.
let options = {
"site": "stackoverflow"
}
stack_badges.badge_recipients( options, (response) => {
console.log(response);
});
badge_recipients_by_id
Get the recent recipients of the given badges.
let options = {
"site": "stackoverflow"
}
let id = "222"
stack_badges.badge_recipients_by_id(id, badges_options, (response) => {
console.log(response);
});
badge_by_tags
Get all tagged-based badges in alphabetical order.
let options = {
"order": "desc",
"sort": "popular",
"site": "stackoverflow"
}
stack_badges.badge_by_tags(options, (response) => {
console.log(response);
});
tags section
let tags_options = {
"site": "stackoverflow",
"key": "your_key"
}
const stack_tags = stackexchange.tags;
tags
Get the tags on the site.
stack_tags.tags(tags_options, (response) => {
console.log(response);
});
tags by name
Get tags on the site by their names.
let tag_name = "nodejs"
stack_tags.tags_by_name(tag_name, tags_options, (response) => {
console.log(response);
});
moderator only tags
Get the tags on the site that only moderators can use.
stack_tags.moderator_only_tags(tags_options, (response) => {
console.log(response);
});
require tags
Get the tags on the site that fulfill required tag constraints.
stack_tags.require_tags(tags_options, (response) => {
console.log(response);
});
tag synonyms
Get all the tag synonyms on the site.
stack_tags.tag_synonyms(tags_options, (response) => {
console.log(response);
});
faqs by tags
Get frequently asked questions in a set of tags.
let tag_name = "nodejs"
stack_tags.faqs_by_tags(tag_name, tags_options, (response) => {
console.log(response);
});
related tags
Get related tags, based on common tag pairings.
let tag_name = "nodejs"
stack_tags.related_tags(tag_name, tags_options, (response) => {
console.log(response);
});
synonyms by tags
Get the synonyms for a specific set of tags.
let tag_name = "nodejs"
stack_tags.synonyms_by_tags(tag_name, tags_options, (response) => {
console.log(response);
});
top answerers on tags
Get the top answer posters in a specific tag, either in the last month or for all time.
let tag_name = "java"
stack_tags.top_answerers_on_tags(tag_name, tags_options, (response) => {
console.log(response);
});
top askers on tags
Get the top question askers in a specific tag, either in the last month or for all time.
let tag_name = "java"
stack_tags.top_askers_on_tags(tag_name, tags_options, (response) => {
console.log(response);
});
wikis by tags
Get the wiki entries for a set of tags.
let tag_name = "java"
stack_tags.wikis_by_tags(tag_name, tags_options, (response) => {
console.log(response);
});
const stack_comments = stackexchange.comments;
Get all comments on the site. comments_options can be empty object.
let comments_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_comments.comments(comments_options, (response) => {
console.log(response);
});
Get comments identified by a set of ids.
let comments_options = {
"key": "your_key",
"access_token": "your_token"
}
let comment_id = "131321";
stack_comments.comments_by_ids(comment_id, comments_options, (response) => {
console.log(response);
});
Delete a comment identified by its id. auth required
let comments_options = {
"key": "your_key",
"access_token": "your_token"
}
let comment_id = "12135";
stack_comments.delete_comment(comment_id, comments_options, (response) => {
console.log(response);
});
Edit a comment identified by its id. auth required. body is required in options
let comments_options = {
"body": "edited comment"
"key": "your_key",
"access_token": "your_token"
}
let comment_id = "12135";
stack_comments.edit_comment(comment_id, comments_options, (response) => {
console.log(response);
});
Casts a flag on the given comment. auth required. option_id is required in options
let comments_options = {
"option_id": "1323"
"key": "your_key",
"access_token": "your_token"
}
let comment_id = "12135";
stack_comments.create_comment_flag(comment_id, comments_options, (response) => {
console.log(response);
});
Returns valid flag options for the given comment. auth required
let comments_options = {
"key": "your_key",
"access_token": "your_token"
}
let comment_id = "12135";
stack_comments.comment_flag_options(comment_id, comments_options, (response) => {
console.log(response);
});
Casts an upvote on the given comment. auth required
let comments_options = {
"key": "your_key",
"access_token": "your_token"
}
let comment_id = "12135";
stack_comments.upvote_comment(comment_id, comments_options, (response) => {
console.log(response);
});
Undoes an upvote on the given comment. auth required
let comments_options = {
"key": "your_key",
"access_token": "your_token"
}
let comment_id = "12135";
stack_comments.undo_upvote_comment(comment_id, comments_options, (response) => {
console.log(response);
});
posts section
const stack_posts = stackexchange.posts;
posts
Get all posts (questions and answers) in the system. posts_options can be empty object.
let posts_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_posts.posts(posts_options, (response) => {
console.log(response);
});
posts_by_ids
Get all posts identified by a set of ids. Useful for when the type of post (question or answer) is not known.
let posts_options = {
"key": "your_key",
"access_token": "your_token"
}
let post_id = "45934757";
stack_posts.posts_by_ids(post_id, posts_options, (response) => {
console.log(response);
});
Get comments on the posts (question or answer) identified by a set of ids.
let posts_options = {
"key": "your_key",
"access_token": "your_token"
}
let post_id = "45934757";
stack_posts.comments_on_posts(post_id, posts_options, (response) => {
console.log(response);
});
Create a new comment on the post identified by id. auth required. the comment should be included in options as body.
let posts_options = {
"body": "Adding test comment"
"key": "your_key",
"access_token": "your_token"
}
let post_id = "45934757";
stack_posts.create_comment(post_id, posts_options, (response) => {
console.log(response);
});
Renders a hypothetical comment on the given post.
let posts_options = {
"key": "your_key",
"access_token": "your_token"
}
let post_id = "45934757";
stack_posts.render_comment(post_id, {}, (response) => {
console.log(response);
});
revisions_by_ids
Get revisions on the set of posts in ids.
let posts_options = {
"key": "your_key",
"access_token": "your_token"
}
let post_id= 39892422;
stack_posts.revisions_by_ids(post_id, posts_options, (response) => {
console.log(response);
});
posts_on_suggested_edits
Get suggested edits on the set of posts in ids.
`
let posts_options = {
"key": "your_key",
"access_token": "your_token"
}
let post_id= 39892422;
stack_posts.posts_on_suggested_edits(post_id, posts_options, (response) => {
console.log(response);
});
search section
const stack_search = stackexchange.search;
search
Search the site for questions meeting certain criteria. search_options must contain one of tagged or intitle field.
let search_options = {
"tagged": "nodejs",
"key": "your_key",
"access_token": "your_token"
}
stack_search.search(search_options, (response) => {
console.log(response);
});
advanced_search
Search the site for questions using most of the on-site search options. for more search_options please visit advanced_search endpoint of stackexchange.
let search_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_search.advanced_search(search_options, (response) => {
console.log(response);
});
similar
Search the site based on similarity to a title. title must be set in search_options.
let search_options = {
"title": "npm install error",
"key": "your_key",
"access_token": "your_token"
}
stack_search.similar(search_options, (response) => {
console.log(response);
});
excerpt_search
Searches a site. For more search_options see excerpt_search endpoint of stackexchange.
let search_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_search.excerpt_search(search_options, (response) => {
console.log(response);
});
suggested_edits section
let suggested_edits_options = {
"key": "your_key",
"access_token": "your_token"
}
const stack_suggested_edits = stackexchange.suggested_edits;
suggested_edits
Get all the suggested edits on the site. options is optional, can be an empty object
stack_suggested_edits.suggested_edits(suggested_edits_options, (response) => {
console.log(response);
});
suggested_edits_by_ids
Get the suggested edits identified by a set of ids. options is optional, can be an empty object
let suggested_edit_id = "3445738"
stack_suggested_edits.suggested_edits_by_ids(suggested_edit_id, suggested_edits_options, (response) => {
console.log(response);
});
network section
These methods return data across the entire Stack Exchange network of sites. Accordingly, you do not pass a site parameter to them.
const stack_network = stackexchange.network;
Access Tokens
invalidate_access_tokens
Allows an application to dispose of access_tokens when it is done with them.
let invalidate_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_network.invalidate_access_tokens(invalidate_options, (response) => {
console.log(response);
});
read_access_tokens
Allows an application to inspect access_tokens it has, useful for debugging.
let read_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_network.read_access_tokens( read_options, (response) => {
console.log(response);
});
Applications
application_de_authenticate
Allows an application to de-authorize itself for a set of users.
let read_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_network.application_de_authenticate( read_options, (response) => {
console.log(response);
});
Errors
errors
Get descriptions of all the errors that the API could return.
let read_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_network.errors( read_options, (response) => {
console.log(response);
});
simulate_errors
Simulate an API error for testing purposes.
let read_options = {
"key": "your_key",
"access_token": "your_token"
}
let error_id = "401";
stack_network.simulate_errors(error_id, read_options, (response) => {
console.log(response);
});
Filters
create_filter
Create a new filter.
let read_options = {
"include": ".quota_max",
"exclude": ".quota_remaining",
"unsafe": false
"key": "your_key",
"access_token": "your_token"
}
stack_network.create_filter(create_filter_options, (response) => {
console.log(response);
});
read_filter
Decode a set of filters, useful for debugging purposes.
let read_options = {
"key": "your_key",
"access_token": "your_token"
}
let filter = ".quota_max"
stack_network.read_filter(filter, read_options, (response) => {
console.log(response);
});
Inbox
Inbox
Get a user's inbox, outside of the context of a site. auth required
let inbox_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_network.inbox(inbox_options, (response) => {
console.log(response);
});
inbox_unread
Get the unread items in a user's inbox, outside of the context of a site. auth required
let inbox_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_network.inbox_unread(inbox_options, (response) => {
console.log(response);
});
Notifications
notifications
Get a user's notifications, outside of the context of a site. auth required
let inbox_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_network.notifications(inbox_options, (response) => {
console.log(response);
});
unread_notifications
Get a user's notifications, outside of the context of a site. auth required
let inbox_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_network.unread_notifications(inbox_options, (response) => {
console.log(response);
});
Sites
sites
Get all the sites in the Stack Exchange network.
let inbox_options = {
"key": "your_key",
"access_token": "your_token"
}
stack_network.sites(inbox_options, (response) => {
console.log(response);
});
info section
let info_options = {
"site": "stackoverflow"
}
const stack_info = stackexchange.info;
info
Get information about the entire site.
stack_info.info(info_options, (response) => {
console.log(response);
});
privilages section
let privilages_options = {
"site": "stackoverflow",
"key" : "your_key"
}
const stack_privilages = stackexchange.privilages;
privilages
Get all the privileges available on the site.
stack_privilages.privilages(privilages_options, (response) => {
console.log(response);
});
revisions section
let revisions_options = {
"site": "stackoverflow",
"key" : "your_key"
}
const stack_revisions = stackexchange.revisions;
revisions
Get all revisions identified by a set of ids.
let ids = "BCF73AEC-7F9D-4623-8C38-66E481B52513"
stack_revisions.revisions( ids , revisions_options, (response) => {
console.log(response);
});
events section
To use events endpoint you need to have access_token and key, you can generate your access_token and key here.
let event_options = {
"site": "stackoverflow",
"key": "your_key",
"access_token": "your_token"
}
const stack_events = stackexchange.events;
events
Get recent events that have occurred on the site. Effectively a stream of new users and content. auth required
stack_events.events(event_options, (response) => {
console.log(response);
});
Table of Content
The module exposes following endpoints of stackexchange api:
Endpoints | Description | See in StackExchange |
---|
info | Get information about the entire site. | info |
Endpoints | Description | See in StackExchange |
---|
privilages | Get all the privileges available on the site. | privileges |
Endpoints | Description | See in StackExchange |
---|
events | Get recent events that have occurred on the site. Effectively a stream of new users and content. auth required | events |