You have 2 questions:
"How do I exclude records based on the presence of a certain field?"
Answer: The API will not do this for you; your code must filter out these results.
"(How do I ) return only open questions?"
Answer: Use the /search/advanced route.
Exclude records where field is present:
The API does not do this for any field, and seems unlikely to add the capability. (See this somewhat related answer to "API responses are sometimes missing fields".}
Your app/script must loop through the results and exclude the ones you are not interested in.
For example, this query to /questions
:
/2.2/questions?tagged=notifications&site=stackapps
returns:
{ "items": [ {
"title": "Top Bar for Chat Rooms"
}, {
"title": "Get our Stack Exchange inbox as native notification on Chrome"
...
}, {
"closed_date": 1382175473,
"title": "Mark notification/inbox item as read"
}, {
"title": "Trying to get the Total results count crashes the /notifications path"
...
} ],
"total": 13
}
Your code would loop through that and reject items where typeof closed_date != "undefined
.
Return only open questions:
For such "complex" queries, the /search/advanced
route was added.
There you have two options:
You can use the closed=False
parameter provided:
/2.2/search/advanced?closed=False&tagged=notifications&site=stackapps
Or you can leverage the q
parameter -- which mimics much of the functionality of the website search:
/2.2/search/advanced?q=closed:no&tagged=notifications&site=stackapps