5

How can I get the Categories and Keyword hierarchy using OData?

When I tried to retrieve Keywords using [OData Service Object].Keywords, I get all of the Keywords. However, the parent is null and children count is 0, so I am unable to create the hierarchy.

Also, how can I get the Components and/or Pages that are associated to each Keyword using OData?

7

Try the below OData query to get the Parent and Child keyword hierarchy details.

/odata.svc/Publications(362)/Keywords/?$expand=Children,Parent

This is one web service call and once you have the results, use LINQ to query for a specific keyword.

The above using OData expand option to get Parent and Child node details.

e.g; expand=Node1 --> expands Node1
expand=Node1,Node2 --> expands Node1 and Node2.

Hope this will help.

| improve this answer | |
  • Good thinking Ram. I had totally forgot about $expand. I had edited my answer and +1 for you. – Nickoli Roussakov Jul 29 '13 at 18:22
  • Consider also accepting the answer as an "official" thanks to Ram and also to show others what answered the question. – Alvin Reyes Jul 29 '13 at 22:28
5

If you look at http://myserver.com/odata.svc/Keywords you'll see a linear collection of Keyword entities. Keywords that are nested within other Keywords (i.e. Children) will have a <link href=".../Parent" /> property point to the parent keyword, while any Keywords that have nested Keyword (i.e. Parents) will have HasChildren=true and <link href=".../Children /> point to a list of child Keyword entities.

The way that you can traverse the tree is by making separate web service calls to either get children or get parents via the <link> properties. As Ram mentioned you can use $expand to get the relationships in one call.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.