How to get the full topic list from the Category API
Solved
Technical Support
-
Hi,
I'm using api/topic/{category_id} API and it is only returning the first 40 topics. I've tried to figure out how the lazy loading works but can't see any network request in Chrome developer tools.
I'd love some help with how to get the full list or how to get the next 40. My largest category has 248 topics so I think it would be fine to get the full list.
-
Hi Joel,
You can write some javascript code to get all the topics in a category, here is a sample that loops until all pages are loaded.
const topics = []; let done = false; let page = 1; while(!done) { const d = await $.get(`/api/category/21/tutorials?page=${page}`); topics.push(...d.topics); if (d.pagination.next && d.pagination.next.page > page) { page = d.pagination.next.page; } else { done = true; } } console.log(`done, got ${topics.length} topics`);
-
Thank you! that is exactly what I needed.
-
Copyright © 2024 NodeBB | Contributors