Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • John Churchley 272 posts 1258 karma points c-trib
    Jun 16, 2015 @ 13:16
    John Churchley
    0

    Custom Dashboard using WebApi

    I'm trying to create a group of custom dashboard boards. I've created a separated class library and referenced it in my Umbraco web project.

    namespace Dashboards
    {
        [Umbraco.Web.Mvc.PluginController("Dashboard")]
        [IsBackOffice]
        public class WelcomeController : UmbracoApiController
        {
            public int countPublishedNodes()
            {
                var contentService = Services.ContentService;
                int PublishedNodes = contentService.CountPublished();
    
                return PublishedNodes;
            }
        }
    }
    

    However I'm getting a 404 error when I try and access the method /umbraco/backoffice/api/Dashboard/Welcome/countPublishedNodes

    can anyone see why? do I need to map it in an startup event ?

  • Jamie Pollock 174 posts 853 karma points c-trib
    Jun 16, 2015 @ 14:33
    Jamie Pollock
    0

    Hi John,
    I've not used the [IsBackOffice] with UmbracoApiController but I've had great success using the UmbracoAuthorizedApiController .

    Try the following code:

    namespace Dashboard {
        [Umbraco.Web.Mvc.PluginController("Dashboard")]
        public class WelcomeController : Umbraco.Web.WebApi.UmbracoAuthorizedApiController {
            [System.Web.Http.HttpGet]
            public int countPublishedNodes() {
                var contentService = Services.ContentService;
                int PublishedNodes = contentService.CountPublished();
    
                return PublishedNodes;
            }
        }
    }
    

    [HttpGet] is required as by default it's considered a HTTP Post request and will disallow any access. UmbracoAuthorisedApiController will ensure the user is authorized before they make the request.

    I hope this helped :)

    Thanks,
    Jamie

  • John Churchley 272 posts 1258 karma points c-trib
    Jun 18, 2015 @ 15:43
    John Churchley
    0

    Thanks for the reply I'll give it ago in the next few days!

  • Jamie Pollock 174 posts 853 karma points c-trib
    Jun 18, 2015 @ 15:45
    Jamie Pollock
    0

    Awesome, if it helps you out mark it as the solution. Otherwise let me know and we'll see what we can do, eh?

Please Sign in or register to post replies

Write your reply to:

Draft