Is there a way to get all the posts from a certain category by a specific user?
AI-generated summary
Getting Posts from a Specific Category
chenny408 is looking for a way to retrieve all posts from a specific category by a certain user. cpradio suggests using the search URL with parameters, such as https://meta.discourse.org/search?q=category%3Abug%20user%3Acpradio. chenny408 then asks how to get the raw data and riking provides the JSON version of the search URL: https://meta.discourse.org/search.json?q=category%3Abug+user%3Acpradio.
To use the Discourse API Ruby gem, chenny408 shares the search function, but struggles to create the right parameters. cpradio suggests sending a simple HTTP GET request, replacing the q= string. riking provides the correct Ruby code: api_object.get('/search', {q: 'category:bug user:cpradio'}).
Something like this?
https://meta.discourse.org/search?q=category%3Abug%20user%3Acpradio
i didnt see it in any of the posts.. is there a specific URL i can query?
Don’t look at the results, look at the URL and how it is querying for a category and a specific user.
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.
awesome thanks.. anyone know how to use the Ruby gem to call this?
https://github.com/discourse/discourse_api
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
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=
Looks like it would be api_object.get('/search', {q: 'category:bug user:cpradio'})