I want to use the Stack Exchange API to perform research on the question/answer's body but it seems impossible.
Is that the case? If not, how do I go about doing it?
In order to access the body of a post, you need to create a filter that includes this information. You create a filter using the /filters/create
method:
http://api.stackexchange.com/2.0/filters/create?include=question.body;answer.body
The response from that URL will look something like this:
{
"items": [{
"filter":"!9Tk5izFWA",
...
}
As you can see, the new filter is identified by the string !9Tk5izFWA
. You need to then pass this as the filter
parameter to any request that you want to obtain the post body on.
Example:
http://api.stackexchange.com/2.0/questions?site=stackoverflow&filter=!9Tk5izFWA
Edit: upon further clarification, the method you are looking for is /search
. The example would now become:
http://api.stackexchange.com/2.0/search?site=stackoverflow&filter=!9Tk5izFWA&intitle=java
This example will search for all questions that contain the string "java" in the title.
In the 2.2 version of the API a new end-point /search/advanced got added.
Search the site for questions using most of the on-site search options.
That API does take a body parameter, allowing you to find only questions with a certain term in the body.
Here is how you use it to find questions with the word search in it:
The items array returns instances of the question type.
Unfortunately it will not return answers.
/search/advanced
route, added in API version 2.1, allows you to search on question bodies (not answers, alas) using theq
parameter.