The API route to flag an answer has a couple of issues. The first of these may or may not be a bug, but the second definitely is.
Firstly, sending a request that's apparently identical to the example request that the API console sends fails. On trying to flag Stack Overflow answer #40769255, the API console sends the following parameters to https://api.stackexchange.com/2.2/answers/40769255/flags/add
:
id: 40769255 option_id: 22992 key: my API key access_token: my write token preview: true filter: default site: stackoverflow
When I send a similar (semantically identical, apart from the lack of filter
parameter) request from my Rails web app to https://api.stackexchange.com/2.2/answers/40769255/flags/add
:
option_id: 22992 key: my API key preview: true access_token: my write token site: stackoverflow id: 40769255
I get the following 400 Bad Request:
{"error_id":400,"error_message":"comment","error_name":"bad_parameter"}
I've also tried including a comment
parameter. With an empty parameter, this fails with the same error. With a 16-character comment
parameter, the request succeeds (for a NAA flag, which doesn't require a comment). Which leads me on to bug #2...
The flag doesn't get created.
As I said, I was trying to flag #40769255 on Stack Overflow. After the successful request, I opened the flag menu on the answer, expecting it to tell me that I have an NAA flag cast. It doesn't.
Neither does my flag history list any flags on that answer.
This is definitely a bug, since the API request should not return a 200 OK unless the flag has actually been created.
option_id: 22992
is "other" which does require a comment