Get list of topics client side

javascript

#1

Hey Guys,

I’ve been trying to find documentation/posts on how to retrieve a list of topics using client side code - and, if possible, filter these topics by one or more tags and preferably more than one category. I don’t want a whole page, just an object that I can manipulate client side etc.

I’ve seen one example that seeks to render topics in tiles, but from what I can see it returns a whole page, not a fragment.

Any help would be appreciated.

Many thanks.


(Apparently Archetype) #2

/latest.json is what you want i think.

that will get you a JSON object, poking around in it a bit you find a list of topics (and elsewhere a link to the next “page” of topics)

a topic entry looks like this:

 {
    "id": 37587,
    "title": "Get list of topics client side",
    "fancy_title": "Get list of topics client side",
    "slug": "get-list-of-topics-client-side",
    "posts_count": 1,
    "reply_count": 0,
    "highest_post_number": 1,
    "image_url": null,
    "created_at": "2016-01-07T13:03:53.247Z",
    "last_posted_at": "2016-01-07T13:03:53.356Z",
    "bumped": true,
    "bumped_at": "2016-01-07T13:03:53.356Z",
    "unseen": false,
    "last_read_post_number": 1,
    "unread": 0,
    "new_posts": 0,
    "pinned": false,
    "unpinned": null,
    "visible": true,
    "closed": false,
    "archived": false,
    "notification_level": 1,
    "bookmarked": false,
    "liked": false,
    "views": 17,
    "like_count": 0,
    "has_summary": false,
    "archetype": "regular",
    "last_poster_username": "ccdw",
    "category_id": 6,
    "pinned_globally": false,
    "tags": ["javascript"],
    "posters": [{
        "extras": "latest single",
        "description": "Original Poster, Most Recent Poster",
        "user_id": 18201
    }]
}

should get you what you need.you can also just get the topics in a category, such as /c/support.json


#3

that’s great @accalia

Thanks so much.


(Apparently Archetype) #4

Not a problem, happy to help.