I'm using this code and works great to pull courses with an End Date, but the problem is, its pulling all courses no matter what semester it is. We do not remove instructors from past courses so to accomplish what I would like is to filter the api call to pull only the current semester.
I think I have this wrong - const response = await fetch(`ourD2Ldomain/d2l/api/lp/1.42/enrollments/myenrollments/?orgUnitTypeId=3&orgUnitId=${termId}`); but I'm just not sure what it is.
<p></p>
<ul id="codeList"></ul>
<p>
<script>
async function getCourses() {
const termId = '2941214'; // Replace with the desired term ID
const response = await fetch(`ourD2Ldomain/d2l/api/lp/1.42/enrollments/myenrollments/?orgUnitTypeId=3&orgUnitId=${termId}`);
const data = await response.json();
const codeList = document.querySelector('#codeList');
data.Items.forEach(item => {
const code = item.OrgUnit.Code;
const id = item.OrgUnit.Id;
const endDate = new Date(item.Access.EndDate); // Parse the date string using the Date object
endDate.setDate(endDate.getDate() - 7); // Subtract 7 days from the date
const formattedDate = endDate.toLocaleDateString(); // Format the date string to display only the day, month, and year
const li = document.createElement('li');
const a = document.createElement('a');
a.textContent = code + " (" + formattedDate + ")"; // Use the formatted date string in the link text
a.href = 'ourD2Ldomain/d2l/home/' + encodeURIComponent(id);
li.appendChild(a);
codeList.appendChild(li);
});
}
getCourses();
</script>
</p>