How do I get all posts from a specific category?


(Chenny408) #1

Is there a way to get all the posts from a certain category by a specific user?


(cpradio) #2

Something like this?
https://meta.discourse.org/search?q=category%3Abug%20user%3Acpradio


(Chenny408) #3

i didnt see it in any of the posts… is there a specific URL i can query?


(cpradio) #4

Don’t look at the results, look at the URL and how it is querying for a category and a specific user.


(Chenny408) #5

thanks got it, is there any way to get the raw data? i saw a search() function in the API, but not sure how to include the parameters.


(Kane York) #6

gives you

https://meta.discourse.org/search.json?q=category%3Abug+user%3Acpradio


(Chenny408) #7

awesome thanks… anyone know how to use the Ruby gem to call this?

I see in the source code, but wasnt able to create the right parameters to successfully retrieve the query results.

  # @param term [String] a search term
  # @param options [Hash] A customizable set of options
  # @option options [String] :type_filter Returns results of the specified type.
  # @return [Array] Return results as an array of Hashes.
  def search(term, options={})
    response = get('/search/query', options.merge(term: term))
    response[:body]
  end

(cpradio) #8

Sorry, I’m not very keen on Ruby, but it should be as simple as sending a HTTP Get request to https://meta.discourse.org/search.json?q=category%3Abug+user%3Acpradio and just replacing the string sent as q=


(Kane York) #9

Looks like it would be api_object.get('/search', {q: 'category:bug user:cpradio'})