API to Retrieve and Update User's AOU/Department Level Role in Brightspace?

Is there an API in Brightspace that allows me to retrieve a user's role at the AOU (Authorised Operating Unit) or department level? Additionally, is there an API that allows updating a user's role at the AOU/department level? If so, could you please provide the endpoint details and any relevant documentation?
Best regards,
Kabir
Answers
-
Hi Kabir
To retrieve the enrollment details for a given user at a given OU, use this:
https://docs.valence.desire2learn.com/res/enroll.html#actions:~:text=LP%20API%20v1.26.-,GET%20/d2l/api/lp/(version)/enrollments/orgUnits/(orgUnitId)/users/(userId),-%C2%B6Enrollment Data looks like this:
To perform an enrollment, use this:
https://docs.valence.desire2learn.com/res/enroll.html#actions:~:text=the%20user.-,POST%20/d2l/api/lp/(version)/enrollments/,-%C2%B6You will need to provide this JSON data block:
I hope that's helpful
Matt
Learning Administration Manager -
You can use the Users Brightspace Data Set (BDS) to look up UserId values, Organizational Units BDS to look up OU#s and the Role Details BDS to look up RoleId values (from the Data Hub tool).
Matt
-
Hi Matt,
Thank you for your help. Now my custom widget is ready, but in my custom widget, I have a function to check the user role before enrolling a user, but it’s not working as expected. The reason appears to be hardcoded values for {orgUnitId} and {userId} in the fetch URL.
For example, the problematic line looks like this:
const res = await fetch(`${API}/enrollments/orgUnits/$123456/users/$789101`, {
I replaced the hardcoded values with template literals using variables:
const res = await fetch(`${API}/enrollments/orgUnits/${orgUnitId}/users/${userId}`, {
However, the code keeps reverting to the hardcoded values. Note that the hardcoded orgUnit value corresponds to the org unit where my widget currently runs, and the hardcoded userId corresponds to my user ID.
I have tried the following troubleshooting steps without any improvement:
- Reverting the fetch line back to use the variables:
- const res = await fetch(`${API}/enrollments/orgUnits/${orgUnitId}/users/${userId}`, {
- Performing a hard-refresh in the browser:
- Windows: Ctrl + F5
- In Dev Tools → Network tab, checking Disable cache and then reloading
- Deleting the old HTML content and replacing it with the updated file containing the correct getEnrollment() code
Here is the function I am using:
async function getEnrollment(orgUnitId, userId) {
try {
const res = await fetch(`${API}/enrollments/orgUnits/${orgUnitId}/users/${userId}`, { headers: HEADERS });
if (res.status === 404) return null;
if (!res.ok) throw new Error(`Failed to check enrollment: ${res.status}`);
return await res.json(); // Full response with RoleId
} catch (err) {
console.error(`Enrollment check failed for user ${userId} in ${orgUnitId}:`, err);
return null;
}
}
Despite all the above, the hardcoded values keep reappearing in the code, which is breaking the enrollment check.
Could you please advise what might be causing this issue and how to fix it?
Best regards,
Kabir