Copied to clipboard

Flag this post as spam?

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


  • Allan Blaabjerg Lange 9 posts 91 karma points
    Jul 10, 2019 @ 06:51
    Allan Blaabjerg Lange
    0

    How do I access content from outside of Umbraco

    Hi everyone

    I would like to access content from outside of Umbraco on a web based system. Is it at all possible and how would one go about doing this?

    Is there an API for accessing my content in Umbraco?

  • Phil Atkinson 51 posts 244 karma points
    Jul 10, 2019 @ 08:40
    Phil Atkinson
    0

    There is a "headless" addition to umbraco that lets you do this, as well as the older API repo add-on. This is very popular at the moment and is how we use umbraco too

  • Allan Blaabjerg Lange 9 posts 91 karma points
    Jul 11, 2019 @ 13:39
    Allan Blaabjerg Lange
    0

    Thank you.

    I will have a look at this in the near future, hopefully it is the answer to my issue.

  • Allan Blaabjerg Lange 9 posts 91 karma points
    Jul 24, 2019 @ 05:54
    Allan Blaabjerg Lange
    0

    I have tried installing the Rest API and followed this post (https://24days.in/umbraco-cms/2015/umbraco-rest-api/) but with no luck.

    I have not been able to get it running. Is it possible that the post/guide from 24days is missing anything?

    FYI: The website is running on an Umbraco v. 7.6.13.

    Thanks in advance

  • Jan Skovgaard 11242 posts 23414 karma points MVP 6x admin c-trib
    Jul 24, 2019 @ 06:05
    Jan Skovgaard
    100

    Hi Allan

    The Rest API package is outdated, which it also says in the GitHub repository and in the documentation here on our. I'll make sure we get Marcin's article at 24days.in/umbraco-cms tagged as "outdated" or something similar so more people don't waste their time and pull their hair out after trying to follow it :-)

    Since you already have a site setup I would say that you need to have a look at using WebAPI here https://our.umbraco.com/documentation/Reference/Routing/WebApi/

    Using WebAPI you can make some API endpoints, which can be called from elsewhere.

    If you're on the lookout for something that is pure headless and does not need a traditional CMS setup then Umbraco Headless should be released in Q3 2019.

    Also there is Umbraco HeadRest project by Matt Brailsford using WebAPI that you can explore further here https://github.com/mattbrailsford/umbraco-headrest

    /Jan

  • Allan Blaabjerg Lange 9 posts 91 karma points
    Jul 24, 2019 @ 06:13
    Allan Blaabjerg Lange
    1

    Hi Jan

    Thank you so much. I noticed that the Rest API was discontinued. But I thought it might still worked with my Umbraco installation.

    I will definitely give the WebAPI a go and might even have a look at Matt's Umbraco HeadRest project. He usually makes some pretty awesome stuff.

  • Allan Blaabjerg Lange 9 posts 91 karma points
    Jul 25, 2019 @ 08:23
    Allan Blaabjerg Lange
    0

    Hi Jan

    Using WebAPI in this case was the perfect solution. I have one minor challenge though that I think you might be able to help me with.

    I have set up a doctype with some textboxes, a couple of media pickers and a content picker.

    I have been able to get the contents from the textboxes and the content picker as strings and in case of the content pickers content made a NiceUrlWithDomain string.

    I need to be able to do the same thing with my images from my media pickers, but I haven't been able to. Do you have an idea of how to do this?

    Below you can see my (in progress) code for my api method.

    [HttpGet, Route("getpromoslides")]
        public dynamic GetPromoSlides()
        {  
    
            var promoSlides = Umbraco.Content(7039);
            var list = new List<PromoSlide>();
    
            foreach (var promoSlide in promoSlides.Children)
            {
                var iconMediaId = promoSlide.GetPropertyValue<int>("icon");
                var iconMedia = iconMediaId == 0 ? null : Umbraco.TypedMedia(iconMediaId).Url;
                var iconUri = iconMedia == "#" ? null : iconMedia;
                var buttonLinkPageId = promoSlide.GetPropertyValue<int>("buttonLink");
                var backgroundUriMediaId = promoSlide.GetPropertyValue<int>("backgroundImage");
                var backgroundMedia = backgroundUriMediaId == 0 ? null : Umbraco.TypedMedia(backgroundUriMediaId).Url;
                var backgroundUri = backgroundMedia == "#" ? null : backgroundMedia;
    
                list.Add(new PromoSlide
                {
                    Icon = iconUri, 
                    ThemeTitle = promoSlide.GetPropertyValue("themeTitle"), 
                    Headline = promoSlide.GetPropertyValue("headline"), 
                    Text = promoSlide.GetPropertyValue("text"), 
                    ButtonText = promoSlide.GetPropertyValue("buttonText"), 
                    ButtonLink = Umbraco.NiceUrlWithDomain(buttonLinkPageId), 
                    BackgroundUri = backgroundUri
                });
            }
    
            return list;
        }
    
  • Graham Davis 45 posts 209 karma points
    Jul 26, 2019 @ 14:08
    Graham Davis
    0

    Allan,

    If you are comfortable with jQuery and javaScript, you can do it this way. This my default method that returns the results in an Array.

    var params ={parm1: "value1", param2: "value1" }

    passing no params defaults to GET.

    function ajaxAPI(apiUrl, params, isAsync) {
    
        var postType = "POST"; //passing an object requires a POST
        var ajaxDataType = 'json';
    
        if (isAsync === undefined || isAsync === "" || isAsync === null) {
            isAsync = false;
        }
    
        if (params === undefined || params === "" || params === null) {
            params = "";
            postType = "GET";
            isAsync = false;
        }
    
        try {
            var result = "";
            $.ajax({
                url: apiUrl,
                cache: false,
                type: postType,
                data: JSON.stringify(params),
                async: isAsync,
                dataType: ajaxDataType,
                contentType: 'application/json; charset=utf-8',
                success: function (data) {
                    result = data;
                },
                done: function (data) {
                    result = data;
                },
                fail: function (data) {
                    result = data;
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    //alert('request failed :' + errorThrown);
                }
            });
    
            if (Array.isArray(result) || typeof result === "object" || ajaxDataType === 'html') {
                return result;
            }
            else {
                return JSON.parse(result);
            }
        }
        catch (e) {
            return e;
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft