Forum Discussion

hroppanen's avatar
11 years ago

How to get a list of categories that has tkb articles using REST API call?

Hi,

 

I am going to build a list of five latest tkb articles under each board and category. So in the top I would like to have a category name and link, under it would be a board name and link and under that five latest tkb articles. Like this:

 

TKB category name

TKB board name

1. TKB article

2. TKB article

3. TKB article

4. TKB article

5. TKB article

 

TKB board name 2

1. TKB article

2. TKB article

...

 

I can get all categories using REST API call /restapi/vc/categories/ but how would I be able to get ONLY the categories that has TKB articles within?

 

If that is not possible is there some other way I could do it?

4 Replies

  • I think you'll need to get all the categories first, then go through each and ignore any that don't contain knowledge bases.

     

    Alternatively, if the categories never change, you could just hard code them into your component.

  • Do you mean looping through boards inside every category and see if API call

    /restapi/vc/boards/id/board_name@tkb

    success? That could be a way to do it. Although it seems a little inefficient. 

    I wonder why there isn't a call like

    /restapi/vc/categories/style/tkb/

    or

    /restapi/vc/categories@tkb/

    that could do this?

  • OlivierS's avatar
    OlivierS
    Lithium Alumni (Retired)
    11 years ago

    hroppanen I wonder if you shouldn't wait a bit until the Rest API v2 is public (hopefuly end of this month). You would be able to run select queries with where clause using LiQL.

    Unfortunately, to begin with, the categorie object won't be available, but I don't think you would have to wait long until it's available in LiQL ...

  • hroppanen's avatar
    hroppanen
    Ace
    11 years ago

    OlivierS Thanks for the information! Looking forward to that :)

     

    Unfortunately there is a need for this right now so I am going to build it already with the methods available and maybe go with the LiQL later on.

     

    I made some research and I found a call

    /restapi/vc/nodes/type/key/tkb/nested

     which will return all the tkb boards.

     

    I will use that as a starting point and use a call

    /restapi/vc/boards/id/board_name@tkb/category/

     to get the category name.

     

    For the five latest articles I will use a call

    /restapi/vc/boards/id/board_name@tkb/threads/recent?page_size=5

     I think that should do it.