<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Khan</title>
    <description>The latest articles on DEV Community by Khan (@kabii).</description>
    <link>https://dev.to/kabii</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1492865%2F2996b5ed-a85a-4d7a-82bc-618d678a1137.png</url>
      <title>DEV Community: Khan</title>
      <link>https://dev.to/kabii</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kabii"/>
    <language>en</language>
    <item>
      <title>Why isn't the enrollment API working in my code?</title>
      <dc:creator>Khan</dc:creator>
      <pubDate>Tue, 14 May 2024 11:38:27 +0000</pubDate>
      <link>https://dev.to/kabii/why-isnt-the-enrollment-api-working-in-my-code-45hl</link>
      <guid>https://dev.to/kabii/why-isnt-the-enrollment-api-working-in-my-code-45hl</guid>
      <description>&lt;p&gt;In our staff training course, a new user can create a sandbox for themselves. I'm using the Brightspace (D2L) Whoami, Enrollment, and Create Course APIs. While Whoami and Create Course are working as&lt;br&gt;
expected, the Enrollment API is not. I'm utilising the Enrollment API to search for a sandbox if it's already created and to avoid duplication.&lt;br&gt;
Do you have any advice? Please see the part of the code below.&lt;/p&gt;

&lt;p&gt;// Define the base URL for the Brightspace API endpoint for enrollments&lt;br&gt;
    const baseURL = &lt;code&gt;https://example.com/d2l/api/lp/1.44/enrollments/myenrollments/&lt;/code&gt;;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Define the URL for fetching enrollments with the bookmark parameter
let enrollmentsURL = `${baseURL}?bookmark=6606`;

// Array to store all enrollments
let allEnrollments = [];

// Fetch all pages of enrollments
while (enrollmentsURL) {
  const enrollmentsResponse = await fetch(enrollmentsURL);
  const enrollmentsData = await enrollmentsResponse.json(); // Define enrollmentsData here

  // Add fetched enrollments to the array
  allEnrollments = allEnrollments.concat(enrollmentsData.Items);

  // Check if there are more pages
  if (enrollmentsData.PagingData &amp;amp;&amp;amp; enrollmentsData.PagingData.bookmark) {
    enrollmentsURL = `${baseURL}?bookmark=${enrollmentsData.PagingData.bookmark}`;
  } else {
    enrollmentsURL = null;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;// Check if the course already exists in the user's enrollments&lt;br&gt;
    const courseExists = allEnrollments.some(enrollment =&amp;gt; enrollment &amp;amp;&amp;amp; enrollment.CourseName === uniqueName);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (courseExists) {
  // Display message if the course already exists
  document.getElementById("message").textContent = `Course "${uniqueName}" already exists in your enrollment.`;
  return; // Exit function if course already exists
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>api</category>
    </item>
  </channel>
</rss>
