'Google Classroom API Create Material

I am aware that there are multiple questions essentially asking the same thing, but part of the problem I've identified is a lack of detail in the questions, so I'm going to try here, since I think I've exhausted all possibilities.

In the newer Google Classroom, there is a Classwork Tab/Page. This is new, and replaced an older "About" page. In this page, as a regular web user, you can create various materials, including one simply called "Material." This is done by clicking the create button and choosing "Material". enter image description here

These materials contain any combination of title, description, and attached files/links.

However, when using the API, while I can access any OTHER type of Classwork via: Classroom.Courses.CourseWork, no attempts to find these items (or create them via the API) has been successful. I've successfully created Assignments (a variant of CourseWork using:


Classroom.Courses.CourseWork.create({
    "creatorUserId":'me',
    "state":'draft',
    "courseId":cid,
    "title":'test item',
    "workType":"ASSIGNMENT",
    "materials": [],

  }, 'myClassCode');

}

The enum for workType according to the API only contains: enter image description here

I've tried omitting the workType (receive error saying I need to include it), using various guesses like MATERIAL, NONE, ABOUT, and null (all receive errors for invalid types).

I can query the list of CourseWork and find all of my entries that are questions or assignments but have found no access to the other items, which are current and active in the Classwork page for the class.

It's possible that this simply isn't accessible via the API, but I'd like to confirm. Any advice would be appreciated.

I am running as SuperUser and everything else seems to be working fine.



Solution 1:[1]

You are right, at the moment it is not possible to create course materials through Google Classroom API.

Indeed, there is a feature request for it already:

https://issuetracker.google.com/issues/127591179

I suggest you to give it a star to increase visibility and get updates on the implementation status of the feature.

Solution 2:[2]

Here is code that I have been using

/------------------------------Create Coursework Material-----------------------------------
function createCourseworkMaterial (id, cTitle, cDescription, topicId) {
  var courseArgs = { 
    "title": cTitle,
    "description": cDescription,
    "state" : "DRAFT",
    "topicId": topicId
  };
  try{
    
    Classroom.Courses.CourseWorkMaterials.create(courseArgs,id);

  }catch(e){
    
       console.error('Classroom.Courses.CourseWorkMaterial.create() yielded an error: ' + e);
  }
  
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ziganotschka
Solution 2 Jeremy Caney