2

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?

1
  • The /search/advanced route, added in API version 2.1, allows you to search on question bodies (not answers, alas) using the q parameter. Dec 12, 2018 at 21:16

3 Answers 3

3

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.

3
  • Thank's but sorry again, I want to search in the body not only in the title. I think the api not provide this service.
    – taoder
    Jun 11, 2012 at 14:59
  • @taoder: That is correct - the API does not provide a means of searching within the post body. You could, however, use the data dumps. Jun 11, 2012 at 15:02
  • Yes, I know. I do a comparison between this two method use of the api and the search engine of stackoverflow and in an other hand the use of the data dump.
    – taoder
    Jun 12, 2012 at 8:02
0

It's impossible to search in the body with the api stackexchange.

0

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:

2.2/search/advanced?order=desc&sort=activity&body=search

The items array returns instances of the question type.

Unfortunately it will not return answers.

You must log in to answer this question.

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