Forum Discussion

Gursimrat's avatar
Gursimrat
Leader
12 years ago

REST API: Get ID of current node's category

How can I get the ID of the category inside the board? I want to get the ID of the category for a board and want to display the other boards in that category by getting its ID and using the following REST call 

 

http://community.com/community-name/restapi/vc/categories/id/CAT-ID/boards

 

Moreover, I also want to get the number of post inside the boards which are returned.

 

Thanks

8 Replies

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    12 years ago

    Hi Gursimrat,

     

    rather than via REST, have you tried using the coreNode context object? I think you should be able to retrieve this information by looking for the ID of the coreNode or by looking up at its ancestors.

     

    The documentation can be found here

     

    Regards,

     

  • Gursimrat's avatar
    Gursimrat
    Leader
    12 years ago
    Using ${coreNode.ancestors} gives FreeMarker template error
  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    12 years ago

    That's very odd - it should be fine when called from the context of a board. What error are you getting? Please keep in mind that ancestors is an array so you would need to look into the array elements to find out the information around the node's ancestors.

     

    For example:

    ${coreNode.ancestors[0].id}

     Would return the id of the first ancestor.

  • Gursimrat's avatar
    Gursimrat
    Leader
    12 years ago

    Or is there any widget in Lithium which can display the boards in the current category?

    Lets say Category Animals has boards Tiger, Horse, Rhino, Lion, Elephant etc and when I am inside Board Horse, I should be able to see the other 4 boards inside Animals Category.

     

    Thanks

  • Ok, so ${coreNode.ancestors[0].id} returns the id of the first ancestor. How do you return the id of the page you're currently on? Nothing I try with coreNode is successful. I even tried using coreNode.ancestors?children[0], but it throws a freemarker error. Any help would be much appreciated.
  • sunny_mody's avatar
    sunny_mody
    Advisor
    12 years ago
    I think you would need to make a custom component and get the category id using ${coreNode.ancestors[0].id}, then get the boards from this category using rest api (/restapi/vc/categories/id/${coreNode.ancestors[0].id}) and parse the response to get all boards.

    You would surely need to eliminate the board which are currently on, this can be done using some freemarker logic.

    Thanks