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/add
1, 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).