How to get all pages by document type using Umbraco API and spit out data into Json?
Hi all,
So as the title suggests I have created a document type called 'clients' with a few basic properties, some strings called 'clientname' and 'clientage'.
I've built a controller using the umbracoApi:
[System.Web.Http.Route("api/{controller}")]
public class ApiController : UmbracoApiController
{
[System.Web.Http.HttpGet]
public string GetAllPages()
{
var content = Umbraco.ContentAtRoot().FirstOrDefault().DescendantsOfType("clients");
var stuff = JsonConvert.SerializeObject(content);
return stuff;
}
}
but when I try to call the endpoint in my postman I get this error:
"Self referencing loop detected for property 'ContentType' with type 'Umbraco.Core.Models.PublishedContent.PublishedContentType'. Path '[0].ContentType.PropertyTypes[0]'."
aside from the json output, am I getting the pages correctly via the api?
How to get all pages by document type using Umbraco API and spit out data into Json?
Hi all,
So as the title suggests I have created a document type called 'clients' with a few basic properties, some strings called 'clientname' and 'clientage'.
I've built a controller using the umbracoApi:
but when I try to call the endpoint in my postman I get this error:
"Self referencing loop detected for property 'ContentType' with type 'Umbraco.Core.Models.PublishedContent.PublishedContentType'. Path '[0].ContentType.PropertyTypes[0]'."
aside from the json output, am I getting the pages correctly via the api?
Grateful for any help on the matter!
Andy
Hi Andy.
Instead of returning the serialized string, you should be able to return
IEnumerable<IPublishedContent>
.Not sure whether you would get the same error. But it is worth the try. :-)
Hi! Thanks for your answer.
I changed it to
however I am not getting this error:
The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8
it needs to be serialized into json as I was doing in my initial post, probably not doing it right but unsure where I am going wrong!
Andy
Hmm..
What about the settings they suggest in answer 1: https://stackoverflow.com/questions/13510204/json-net-self-referencing-loop-detected
Does that help? :-)
is working on a reply...