How to retrieve categories for documents

Joel Dahlin asked on February 21, 2014 14:17

I am using REST to retrieve the news items on my site. Is there a way in the same call to retrieve the categories each news item belongs to?

Here is what I have for retrieving the news items: http://localhost/rest/content/fcs/all/news?classnames=cms.news&topn=10

Recent Answers


Juraj Ondrus answered on February 24, 2014 03:59

Hi,

This would require some customization since REST allows you to get one object per call only. The customization would be basically the same. Or, have you tried using the WHERE condition in the query string? It depends what exactly you want and how complex the WHERE condition could be.

Best regards,
Juraj Ondrus

0 votesVote for this answer Mark as a Correct answer

Joel Dahlin answered on February 24, 2014 10:16

Is there a way to view the underlying sql being executed with sql debugging at all?

0 votesVote for this answer Mark as a Correct answer

Joel Dahlin answered on February 24, 2014 12:19

Answering my own original question here with the REST call I am using if anyone else stumbles on this:

http://localhost/rest/content/fcs/all/news?topn=2&classnames=cms.news&columns=newstitle,newssummary,newsreleasedate,documentId&where=DocumentID IN (SELECT DocumentID FROM CMS_DocumentCategory WHERE CategoryID IN(6))&orderby=newsreleasedate desc

Thanks Juraj for suggesting the WHERE condition.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 25, 2014 00:29

Joel,

You can turn on Debugging within the CMS SIte Manager and view all the sql and other things that are being executed.

0 votesVote for this answer Mark as a Correct answer

Brad Chapman answered on November 27, 2014 06:07

Hi Guys. Am I correct in assuming there is no accessible REST object for the linkage between a document and a category that will accept a POST request to create a new linkage? The resolution above would indicate such. I am deep in progress of creating an automation process to create site pages in KENTICO from an external database and the key connector I was planning on using to cluster content items was the Categories. It appears that I may need to use cms.relationship REST object instead? Brad

0 votesVote for this answer Mark as a Correct answer

David Komárek answered on December 3, 2014 09:51 (last edited on December 3, 2014 09:57)

Hi Brad,

The object that holds the relation between the document and the category is the cms.documentcategory:

~/rest/cms.documentcategory

You will need to insert both DocumentID and CategoryID for creation of a new bond.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.