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.
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:
I hope this helps!
-Adam