Accessing site assets via the API


(Mark McClure) #1

###Question
Is it possible to access site assets (such as the site-logo and favicon image) or other information on the site (like the site title) via the API? Preferably, I’d like to do this as a non-validated user without an API key, though that’s not a deal breaker.

###Usage case
A simple search on this site for ‘archive’ makes it clear that archiving Discourse sites is tricky. None other than @codinghorror himself refers to it as much harder than you’d think. In part, I think this is due to the complicated structure of the HTML returned by Discourse. Thus, I’m attempting to write my own archiving tool to generate very vanilla HTML that retrieves all the pertinent information via the API. Obtaining everything needed on categories, topics, posts, and users to reconstruct the discussion list is pretty easy. I don’t see how to get information on the overall site itself, though.

Of course, one option is to scrape the HTML itself and doing so for this relatively small amount of information might not be too bad. Then, that’s exactly what I’m trying to avoid by using the API in the first place. I suppose another option would be to access the information locally using a database dump. Not my preference at the moment.


(Blake Erickson) #2

Seems like you could just scrape the html pretty easily and look for the img tag with the id="site-logo".

Using the API though you should be able to go to this url with your API key:

http://localhost:3000/admin/site_settings

which will return json with all the values you are looking for.


(Mark McClure) #3

@blake Yes, you’re right - the site-logo is easy, as is the site title. The favicon seems trickier, though, as it’s buried in a PreloadStore inside a script. Your recommendation on site settings (with a .json) attached works great though.

Thanks!


(Blake Erickson) #4