2

Background

I would like to create an app for general Stack Overflow browsing to improve upon the UI. One of the things that I am targeting is the lack of certain options in the close dialog. I understand and agree with the reason many options aren't available, like extra sites in the "belongs somewhere else" category, and just more options under off-topic. It can get overwhelming for users, so the most useful ones are presented. However to more adept users the "other" box is often the only tool to explain what's wrong.

Request

I would like an API method to close posts. Preferably it would be generic and allow me to do everything the normal close dialog does. That is to say, get a list of the default reasons (and subreasons), close based on any of those default reasons, or close with an "other" reason.

1 Answer 1

3

This has been implemented in API version 2.2.

To list the available close reasons, make a call to /questions/{id}/close/options. The result will list all valid close reasons, including pre-existing duplicate suggestions and off-topic comments.

You cannot assume that a close option will be available without calling this method to see if it actually is. Always call this before actually attempting to VTC.

Actually closing a question requires a call to /questions/{id}/flags/add1, supplying the ID of the flag/vote you wish to cast.


1 Yes, this is "flag" instead of "close". The documentation for close options explains this away by noting that

Conceptually, closing is a subset of flagging.

Also, remember that users with between 15 and 2999 rep can flag to close, kicking a question into the queue for VTCers to look at.


What /questions/{id}/close/options returns

Each flag/vote type in (response).items has an option_id identifying it for later use. Pass this to /questions/{id}/flags/add to VTC with that reason. Each vote/flag also has a set of three booleans indicating additional data that may be required.

  • requires_question_id

    True for close flag/vote types that reference another question (duplicate). When voting to close, supply the question's ID as question_id.

  • requires_site

    True for close flag/vote types that reference another site (off-topic -> migrate). When voting to close, supply the site's domain or API identifier as target_site. (Note that this will only work if that target site is one of the preset migraton targets. Or, presumably, if you're a ♦.)

  • requires_comment

    True for close flag/vote types that require a detailed explanation (off-topic -> custom). When voting to close, supply arbitrary text as comment.

  • none of the above

    The call to close will be just fine given only the flag/vote's option_id. Applies to (opinion-based, unclear, too broad, duplicate (already chosen), off-topic -> preset).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .