4

I'm trying to beautify the reputation audit. If I want to show the post title for a reputation change event, however, I have a problem -- I don't know if the post ID is relative to a question or an answer.

By poking around with the API a bit, it seems that the only way to get a result in my case is:

  1. call /answers/{id};

Is there a better way of doing this?

1
  • Another non-write feature wanted...
    – Jonathan.
    Commented Jan 18, 2011 at 18:34

2 Answers 2

5

I believe that's a correct approach.

There's a way to optimize it saving one request but it's a little bit unsafe for this bug:

  1. call /questions/{id};

EDIT:
I've just realized that your solution can be optimized easily just removing the /questions/{parent-id}/call;
you don't need it because /answers/{id}; already has the title parameter inside the response.

1
  • 1
    Smart hack - given the current roadmap there are quite some requests to be saved still like so ;) Commented Jan 18, 2011 at 10:05
1

You should be able to achieve this via the non optional "is_question" field of route /revisions/{id}:

   "is_question": {
        "description": "if the post is a question",
        "values": "boolean",
        "optional": false
      },

See for example the results for:

4
  • 2
    Uhm, /revisions route does return the parent-id in case of answer. This would force badp to call /answers anyway to get the parent-id and then /questions to get the title. Commented Jan 18, 2011 at 7:37
  • 1
    Also, the call would return a lot of data I don't care about :)
    – badp
    Commented Jan 18, 2011 at 7:38
  • 1
    @systempuntoout / @badp - both arguments are absolutely correct of course, I got carried away digging the API about a question/answer discriminator for a given post id and lost track of the mentioned use case, despite it being phrased elaborately (i.e. getting the post title either way) - it has been (too) late for me apparently ;) Commented Jan 18, 2011 at 9:46
  • 1
    My comment above is partially correct. The /revision route is not returning the parent-id field but it does not matter because /answers/{id}; returns the title costing just one request. So this is a valid solution too though with a bigger payload. Commented Jan 18, 2011 at 14:24

You must log in to answer this question.

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