1

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.

6
  • 1
    Preview:true means you are not creating a flag, so the second part is not a bug. About the first one, I don't have an idea, perhaps the option_id isn't stable and you should fetch it from the rails app?
    – user315433
    Commented Nov 23, 2016 at 16:47
  • @zaq that explains it. As for the first one, the option_id comes from a previous API request.
    – ArtOfCode
    Commented Nov 23, 2016 at 16:51
  • option_id: 22992 is "other" which does require a comment
    – Cai
    Commented Nov 23, 2016 at 16:52
  • @Cai option IDs change per post
    – ArtOfCode
    Commented Nov 23, 2016 at 17:39
  • @Art you are right, I thought it was available IDs that changed per post not actual IDs
    – Cai
    Commented Nov 23, 2016 at 18:03
  • Too late for me to repro now, since the post is deleted. I wanted to double-check that the option_id was for indeed for NAA. I've been using API to cast NAA flags for a long time, and it works fine for me. The NAA option is indexed [2] in the list returned by /flags/options
    – user315433
    Commented Nov 23, 2016 at 18:04

0

You must log in to answer this question.

Browse other questions tagged .