Copied to clipboard

Flag this post as spam?

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


  • Elliot 1 post 72 karma points
    Jan 30, 2019 @ 10:38
    Elliot
    1

    Getting Content data from the UmbracoAPI (contentResource)

    Hey, so I'm trying to get a list of all my articles that have not been updated for two years so this allows the content to stay fresh.

    I have achieved this with the following code.

    angular.module("umbraco").controller("ArticleNotifyController", function ($scope, userService, contentResource, entityResource) {
    let vm = this;
    let user = userService.getCurrentUser().then(function (user) {
        vm.UserName = user.name;
    });
    async function getArticles(){
    let articles = [];
    contentResource.getChildren(2427)
        .then(function(contentArray) {
            contentArray.items.forEach(child => {
                contentResource.getChildren(child.id)
                .then(function(content) {
                    if (content.items != null){
                        content.items.forEach(article => {
                            let dateNow = new Date(Date.now())
                            let articleDate = new Date(Date.parse(article.updateDate));
                            if(articleDate < dateNow.setMonth(dateNow.getMonth() - 24)){
                                articles.push(article)
                            }
                        })
    
                    }
                });
            });
        });
        return await articles;
    };
    getArticles().then(function(result) {
        console.log(result)
      });
    }); 
    

    this returns my results as expected.

    enter image description here

    But if I try to access one of the objects in the array using: console.log(result[0]);

    I get undefined can someone please tell me what I am doing wrong as I'm not sure how to access this?

    Thanks in advance.

  • Erik Eelman 79 posts 319 karma points
    Jan 30, 2019 @ 11:47
    Erik Eelman
    0

    Can you try if result.data[0] works?

Please Sign in or register to post replies

Write your reply to:

Draft