Forum Discussion

Claudius's avatar
13 years ago

REST: Get current node's category

I'm trying to get hold of the current node's top category via REST API, but would even be happy with just the parent category.

I would love to do something as simple as

http://community.lithium.com/community-name/restapi/vc/messages/id/12/category

 ...but that method path isn't available for a message.

 

No more luck with the context object

${coreNode.ancestors}

 which returns a freemarker template error:

Expecting a string, date or number here, Expression coreNode.ancestors is instead a freemarker.template.SimpleSequence

 

I've come up with a nasty workaroung by first pulling the current message's board and then getting the category via

http://community.lithium.com/lithium/restapi/vc/boards/id/boardname/category 

But I' rather like to avoid nesting two REST calls. 

Please help me getting unstuck here, preferrably close to the initial non-working url.

  • AdamN's avatar
    AdamN
    Khoros Oracle

    Hi Claudius,

     

    There are a couple possible approaches...

     

    To get the category for a a message, you can do something like:

    http://lithosphere.lithium.com/restapi/vc/messages/id/42810/board/category

    This works because "/messages/id/42810" returns a Message object. Since this gives you a Message object, you can call the "board" method by simply appending "/board". This returns a Board object, on which you can call the "category" method by appending "/category".

     

    If you want to go the freemarker route insted, you're on the right track. The problem you're running into is that coreNode.ancestors actually gives you a sequence of objects (nodes), so you can't output it directly. Check out this post I created awhile back on working with coreNode.ancestors:

    http://lithosphere.lithium.com/t5/Growing-Successful-Communities/Retrieve-Title-Name-from-Ancestor/m-p/30135/highlight/true#M3458

     

    I hope this helps!

     

    -Adam

     

     

    • iftomkins's avatar
      iftomkins
      Maven

      This is great for the message level, but how do I get the id/url of the board at the topic level? I tried this on a topic page and it threw an error.

       

      There is an object in the API called "Discussion", which I think is the same as topic, but it has no board parameter.