Can you please point me to a working example of how to return documents or nodes through Web API, or tell me how to modify the above to make it work?
Thanks!
After much trial-and-error and frustration over the lack of documentation, this how I ended up getting it to work...
public class NewsItem
{
public string Headline { get; set; }
public string Body { get; set; }
public DateTime CreateDate { get; set; }
}
public class NewsApiController : UmbracoApiController
{
public List<NewsItem> GetNews()
{
var newsItems = new List<NewsItem>();
var items = Umbraco.ContentAtXPath("//newsItem").Where("Visible").OrderBy("createDate desc");
foreach (var item in items)
{
var newsItem = new NewsItem();
newsItem.Headline = item.GetPropertyValue("newsItemHeadline").ToString();
newsItem.Body = item.GetPropertyValue("newsItemBody").ToString();
newsItem.CreateDate = Convert.ToDateTime(item.CreateDate);
newsItems.Add(newsItem);
}
return newsItems;
}
}
If there are any better or easier ways to accomplish this, please let me know.
Web API Get Documents by Document Type
This query works in a MacroPartial but how can I return the same data in Web API?
This doesn't work because obviously CurrentPage doesn't exist in the current context...
Can you please point me to a working example of how to return documents or nodes through Web API, or tell me how to modify the above to make it work? Thanks!
After much trial-and-error and frustration over the lack of documentation, this how I ended up getting it to work...
If there are any better or easier ways to accomplish this, please let me know.
is working on a reply...