Copied to clipboard

Flag this post as spam?

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


  • Joshua Sherer 10 posts 110 karma points
    Dec 22, 2015 @ 22:00
    Joshua Sherer
    0

    DescendantsOrSelf for /umbraco/backoffice/umbracoapi/ ?

    Hello all. What I'd like to do is by using /umbraco/backoffice/umbracoapi/ , I'd like to make a DescentdantsOrSelf request. I receive the following error, ""No action was found on the controller 'Content' ..." and, I apologize, but I cannot find what actions/methods are available to call for /umbraco/backoffice/umbracoapi/ - Maybe if someone could point me to that documentation that could be a big help. I've looked here: https://umbraco.github.io/Belle/#/api --- but I'm not sure if this is the right API that I'm looking for. Yes, I'm completely confused and would deeply appreciate a lil help :-)

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Dec 23, 2015 @ 18:46
    Marc Goodson
    1

    Hi Joshua

    Are you looking to use a UmbracoAuthorizedApiController in a backoffice dashboard or custom property editor ?

    And then use the Angular.JS service $http.get to make a request to the API endpoint to return some JSON ?

    If your controller class inherits from UmbracoAuthorizedApiController then in your ActionResult you will have access to the Umbraco Helper method via

    Umbraco.

    So you could create an end point like so that accepts the id of the node under which you want the descendants:

     public class MyLovelyController : UmbracoAuthorizedApiController
        {
            [HttpGet]
            public IEnumerable<SimplePocoClass> DescendantsOrSelf(int id)
            {
    
            var CurrentNode = Umbraco.TypedContent(id);
            if (CurrentNode != null)
            {
                return CurrentNode.DescendantsOrSelf().Select(f=>SimplifyObject(f));
            }
            else
            {
                return default(IEnumerable<SimplePocoClass>);
    
            }
        }
        //just to help serialise the response, you only want to return the properties you need
        private SimplePocoClass SimplifyObject(IPublishedContent content)
        {
            return new SimplePocoClass()
            {
                id = content.Id,
                Name = content.Name,
                OtherProperty = content.GetPropertyValue<string>("otherProperty")
            };
        } 
    
    }
    public class SimplePocoClass
    {
        public int id { get; set; }
        public string Name { get; set; }
        public string OtherProperty { get; set; }
    
    }
    

    }

    And in AngularJS, if you inject the 'editorState' umbraco service and '$http' angular service into your angularJS controller you can get the Id of the current node (eg where your property editor is loaded, if you are creating a property editor) and make the request to retrieve the data.

    and use

    var currentNodeId = editorState.current.id;
    $http.get("/umbraco/backoffice/API/MyLovely/DescendantsOrSelf/" + currentNodeId).then(
        function (response) {
             $scope.mylovelydescendants = response.data;
    });
    

    if that helps ?

  • Joshua Sherer 10 posts 110 karma points
    Jan 06, 2016 @ 19:25
    Joshua Sherer
    0

    Hi Marc, thank you so much for your time and your code! I should be getting back to this work soon as my priorities have shifted, so at the very least I wanted to express my appreciation for your correspondence. :-)

Please Sign in or register to post replies

Write your reply to:

Draft