stackexchange-apistackexchange

Get only closed questions from the Stack Exchange api, via /questions?


I want to get only closed questions from /questions of the Stack Exchange API.

I've played around a bit with the filters, and I've come up with something which gives me some JSON like this for each question:

{
      "tags": [
        "c++",
        "opencl",
        "intel"
      ],
      "close_vote_count": 0,
      "title": "Weird OpenCL calls side effect on C++ for loop performance",
      "body": "<p>I'm working on a C++ project using OpenCL. I'm using the CPU as an OpenCL device with the  <a href=\"http://registrationcenter.intel.com/irc_nas/5193/intel_code_builder_for_opencl_2015_ubuntu_5.0.0.43_x64.tgz\" rel=\"nofollow\">intel OpenCL runtime</a></p>[...]"
    },

Now, I want only questions which are closed.

How can I do this ?

(another thing: How could I exclude closed questions from the results ?)


Solution

  • You can easily do this by using the following query:

    SELECT count(*)
    FROM Posts
    WHERE ClosedDate IS NOT NULL
    

    This however does not tell you the reason for the closure, to obtain this you should look into the PostHistoryTable which contains detailed information on all changes related to a post.