Question

I am trying to get a list of all users in our instance of Desire2Learn using a looping structure through the bookmarks however for some reason it continuously loops and doesn't return. When I debug it it is showing massive amounts of users (far more than we have in the system as shown by the User Management Tool. A portion of my code is here:

 public async Task<List<UserData>> GetAllUsers(int pages = 0)
    {
        //List<UserData> users = new List<UserData>();
        HashSet<UserData> users = new HashSet<UserData>();
        int pageCount = 0;
        bool getMorePages = true;

        var response = await Get<PagedResultSet<UserData>>("/d2l/api/lp/1.4/users/");

        var qParams = new Dictionary<string, string>();
        do
        {
            qParams["bookmark"] = response.PagingInfo.Bookmark;
            //users = users.Concat(response.Items).ToList<UserData>();
            users.UnionWith(response.Items);
            response = await Get<PagedResultSet<UserData>>("/d2l/api/lp/1.4/users/", qParams);
            if (pages != 0)
            {
                pageCount++;
                if (pageCount >= pages)
                {
                    getMorePages = false;
                }
            }
        }
        while (response.PagingInfo.HasMoreItems && getMorePages);

        return users.ToList();
    }

I originally was using the List container that is commented out but just switched to the HashSet to see if I could notice if duplicates where being added.

It's fairly simple, but for whatever reason it's not working. The Get<PagedResultSet<UserData>>() method simply wraps the HTTP request logic. We set the bookmark each time and send it on.

The User Management Tool indicates there are 39,695 users in the system. After running for just a couple of minutes and breaking on the UnionWith in the loop I'm showing that my set has 211,800 users.

What am I missing?

Was it helpful?

Solution

It appears that you’ve encountered a defect in this API. The next course of action is for you to have your institution’s Approved Support Contact open an Incident through the Desire2Learn Helpdesk. Please make mention in the Incident report that Sarah-Beth Bianchi is aware of the issue, and I will work with our Support team to direct this issue appropriately.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top