Unable to get pages(linked with page type) using rest api.

Shubham Salaria asked on October 9, 2017 12:44

Hi All,

I have successfully configured rest service according to the https://docs.kentico.com/k10/integrating-3rd-party-systems/kentico-rest-service/configuring-the-rest-service

I got default api data through http://localhost/Kentico10/rest/cms.country but when I use object based rest api, kentico gives me 403 forbidden error. I'm also providing basic authentication key(base64 encoded)in header. My URL http://localhost/Kentico10_5/rest/custom.my_news_articles/currentsite?format=xml custom.my_news_articles is a custom page types and by using it I have created different pages.

Can someone please help me to get pages based on custom page type

Thanks Shubham

Correct Answer

Shubham Salaria answered on October 10, 2017 10:20

Thanks a lot Peter. It really worked for me and I'm new to Kentico so thats why didn't understand the terminology from documentation.

I have one more point here can you please build same url to get document based on category field's value. I don't have idea to include where clause for category field of any specific page type.

It will really help me to understand the rest api and to get category based documents.

Thanks Shubham

0 votesVote for this answer Unmark Correct answer

Recent Answers


David te Kloese answered on October 9, 2017 13:29

Could you try doing a call with a Global Administrator account to see if it's a permission issue?

0 votesVote for this answer Mark as a Correct answer

Shubham Salaria answered on October 9, 2017 13:31

Yes I'm using global administrator account for call. Currently I'm making a call through postman to get a successful call

0 votesVote for this answer Mark as a Correct answer

Shubham Salaria answered on October 9, 2017 13:36 (last edited on October 9, 2017 13:36)

Here is the screenshot for your reference Image Text

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on October 9, 2017 23:45 (last edited on October 9, 2017 23:52)

You didnt form URL correctly: there is a difference when accessing objects like cms.country and documents like your 'custom.my_news_articles'. I assume you've created a custom page type custom.my_news_articles. What you need to do is to form request correctly, i.e. to get documents you have to form different URL: /rest/content/currentsite/<culture>/all/<alias path>

Your document type you pass as URL paramters like ?classnames=cms.article

For example I want to get top 10 english cms.menuItem documents under alias /specialpages:

/rest/content/currentsite/en-us/all/specialpages/?format=json&topn=10&classnames=cms.menuitem

So you URL should be something like (put your alias path in there)

http://localhost/Kentico10_5/rest/content/currentsite/en-us/all/<alias path>?format=xml&classnames=custom.my_news_articles

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on October 11, 2017 04:15 (last edited on October 11, 2017 04:45)

Good to here that. Mark it as an answer so other people can discover it.

I don't think categories field exists, if you have some custom field sure you can use sql syntax: You can look at xml/json returned - your field should be in there and if so then do where=fieldname=value

My assumption is that you want to get documents for given category. This probably can be done in 2 request:

  1. get all of the documents for given category ~/rest/cms.documentcategory?topn=10&format=json&where=categoryid=123
  2. then you can put these documentid in to SQL where : documentid in (123, 456) and encode

~/rest/content/currentsite/en-us/all/specialpages/?format=json&where=documentid+in+%28123%2C+456%29

OR you can do it vice versa: first get all of your documents of given type (like we did before), then check which of them under given category i.e you get back 2 documents with documentid in (123,456).

`~/rest/cms.documentcategory?topn=10&format=json&where=categoryid=123&where=documentid+in+%28123%2C+456%29`

P.S. There has been some discussion about that

P.P.S. On the other hand there are other ways of document classification for example document tags, i.e. you can tag your document with some ID: Image Text

So you encode DocumentTags = 'zzz' : DocumentTags+%3D+%27zzz%27%0D%0A and add it to your query string and it will work!

0 votesVote for this answer Mark as a Correct answer

Shubham Salaria answered on October 11, 2017 08:13

Peter, thanks for this detailed information.

Following rest url fullfil my requirement http://localhost/Kentico10_5/rest/content/currentsite/en-us/all//?Where=Organization='05e0495e-3e64-4aad-a00d-a7e30e3037a7' and Geography='56828c63-0d1f-4df4-9d1e-17f3bc9ebab7'&format=json&classnames=custom.my_news_page

Thanks again for your help

Shubham

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on October 11, 2017 12:45

Excellent! REST in Kentico sometimes seems limited, some people create their own API.

P.S. Normally you mark response as answer or vote for it if you find it helpful. If you find an answer yourself - you mark your response, if someone else helped you you marks theirs responses. A Marked responses automatically moves up to the top of a discussion. People can earn reputation if an answer is voted up (+10 points) or marked as correct (+15 points). This way people earn reputation on devnet :).

0 votesVote for this answer Mark as a Correct answer

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