POST /d2l/api/lp/(version)/(orgUnitId)/groupcategories/ not returning Groups.GroupsJobData

Daniel.M.401
Posts: 13 🌱
I'm not getting back any JSON data from my groupcategories put . I get the response.status ==202 but I can't grab what should be a Group.GroupsJobData. The code does generates the Group Category and the single group that should be in the category. Problem is without the GroupsJobData I can't grab the id of the generated group category. What am I missing?
I was expecting to see something in the response object but it's not there. Code below is just say response.data just for lack of having the object name to grab the returned JSON string.
// POST /d2l/api/lp/${version}/${orgUnitId}/groupcategories/
const sectionID = await getCommunitySectionID(orgUnitId, version);
const settingGrpCategory = {
"Name": "Community Group Course Admins",
"Description": { Content: "Course List", Type: "Text"},
"EnrollmentStyle": 0,
"EnrollmentQuantity": null,
"AutoEnroll": false,
"RandomizeEnrollments": false,
"NumberOfGroups": 1,
"MaxUsersPerGroup": null,
"AllocateAfterExpiry": false,
"SelfEnrollmentExpiryDate": null,
"GroupPrefix": null,
"RestrictedByOrgUnitId": sectionID,
"DescriptionsVisibleToEnrolees": 0
};
const postGroupCategoriesrUrl = `/d2l/api/lp/${version}/${orgUnitId}/groupcategories/`;
const xsrf = localStorage.getItem('XSRF.Token');
const jsonData = JSON.stringify(settingGrpCategory);
const response = await fetch(postGroupCategoriesrUrl,
{
method: 'POST',
headers: new Headers({
'Content-Type': 'application/json',
'X-Csrf-Token': xsrf}),
body: jsonData
}
); // Fetch POST data from the current URL
if (response.status !== 202 ) { //check response from API address for error
throw new Error(`Fetch postGroupCategoriesrUrl error: url: available(${response.url}) status code: ${response.status}.`);
} else {
const communityGrpCategory = response.data;
Comments
-
Looks like you're accessing a field that doesn't exist on the response object. Instead of
const communityGrpCategory = response.data;
you should do
const communityGrpCategory = await response.json();
-
doh! Not enough caffeine. Couldn’t see the forest through the trees.