Retrieving active courses for users in D2L Valence API when dealing with large datasets

I’m working with the D2L Valence API and I’m stuck. I need to get all the current courses for a user. By current, I mean courses where the startDate is before today and the endDate is after today.

I’m using this API endpoint:

/d2l/api/lp/{ver}/enrollments/myenrollments/?orgUnitTypeId=3

The problem is, one user has over 18,000 courses! The API only gives me 100 at a time, so I have to use bookmarks. Like this:

/d2l/api/lp/{ver}/enrollments/myenrollments/?orgUnitTypeId=3&bookmark=12528

But doing this 180 times makes the request time out. I can’t find a way to sort by startDate or endDate. All the courses are marked as active too.

Has anyone figured out how to handle this? Is there another API call that could help? Or maybe a way to sort the data? I’m really stuck here. Any ideas would be great!

hey, have u tried using the GetEnrollmentsPage API call? it lets u filter by start/end dates. might help narrow down the results. also, maybe break it into smaller requests over time instead of all at once? just a thought. good luck with that crazy amount of courses!

Wow, 18,000 courses? That’s a lot to handle! :open_mouth: Have you considered using the Org Units API instead? It might be more efficient for your use case.

You could try something like:

/d2l/api/lp/{version}/orgstructure/?orgUnitType=3&orgUnitCode=active

This should return only active courses, which might cut down your dataset significantly. Then you could filter the results on your end for the date ranges you need.

Another thought - could you split your requests into smaller chunks based on date ranges? Like requesting courses for each month or quarter separately? That might help avoid timeouts.

Have you reached out to D2L support about this? They might have some insider tips for dealing with such large datasets.

What kind of system are you working with that has so many courses per user? I’m really curious about the setup you’re dealing with!

I’ve encountered similar issues when working with large datasets in D2L Valence API. One approach that worked for me was implementing a background job or scheduled task to fetch and cache the course data incrementally. This way, you’re not trying to retrieve all 18,000 courses in a single user session.

You could set up a nightly job that fetches courses in batches, stores them in a local database, and updates the ‘current’ status based on the start and end dates. Then, when a user needs their active courses, you can quickly query your local cache instead of hitting the API repeatedly.

Another option is to leverage D2L’s data export features if available in your instance. You might be able to schedule regular exports of course data, which you can then process offline to maintain an up-to-date list of active courses for each user.

Remember to implement proper error handling and retry mechanisms for your API calls to handle intermittent failures gracefully.