Creating Classroom using App Script


I'm trying to create Google classrooms from a spreadsheet using App Script. I can create the classes successfully, but it's not adding the course materials (1 Doc) to the about page.

This is the code I am using and I've tried using the <a href="https://developers.google.com/classroom/reference/rest/v1/courses/create" rel="nofollow">API reference</a> to no avail.

Can someone please advise me on how to correctly format the courseMaterialSets to include a Google Doc from my drive.

var create = Classroom.Courses.create({ "ownerId": '-My email address-', "name": getData[i][0], "section": getData[i][1], "descriptionHeading": getData[i][2], "description": getData[i][2], "courseMaterialSets" : [{ "title" : 'Course Outline', "materials" : [{ "driveFile" : { "id" : getData[i][5], "title" : 'Course Outline' , "alternateLink": getData[i][4], "thumbnailUrl" : 'https://drive.google.com/uc?export=download&id=-Image ID-', }, } ] } ] }) } Logger.log(create) }

Thank you.


I've updated the code to reflect the suggestions in the comments and logged the value of var create which returns all of the info of the newly created Classroom but with no mention of the course material set.


<a href="https://developers.google.com/classroom/reference/rest/v1/courses#CourseMaterial" rel="nofollow">According to the documentation</a> you have to <a href="https://developers.google.com/classroom/reference/rest/v1/DriveFile" rel="nofollow">specify the DriveFile object</a> with JSON.

"driveFile" : { "id": theDocIdString, "title": theDocTitleString, "alternateLink": urlToFileString, "thumbnailUrl": imgThumbnailString }

You can of course pull all of this data from a sheet or use variables to loop through resources.


Here is the code I tried to successfully create a course, but I also do <strong>not</strong> get the course materials to attach to the ABOUT tab of the Google Classroom created.

function createCourse() { var resource = { name: "XYZ course", room: "The Great Hall", ownerId: "me", courseMaterialSets: [{ title: "course materials", materials: [ { driveFile: { id: "insert id of google drive file" } } ], }], } var newCourse = Classroom.Courses.create(resource); }

I also tried creating the course and then accepting the course in Google Classroom and the trying to add the classroom set. This also was not successful.

function addClassSet() { var id = "course id obtained with sample script in documentation"; var resource = { name: "XYZ course", room: "The Great Hall", courseMaterialSets: [{ title: "course materials", materials: [ { driveFile: { id: "drive file id" //drive file was not added } } ], }], description: "This is a trial course", //this worked } Classroom.Courses.update(resource, id); }

Is it because the <a href="https://developers.google.com/classroom/reference/rest/v1/courses#CourseMaterialSet" rel="nofollow">documentation states</a> that the courseMaterialsSets is Read only???


  • Regex to wrap JSON property value inside another string
  • How to query an IDriveResource in Google Drive for Xamarin.Android using the Drive API?
  • How to remove a parent from a file or folder in google app script
  • Golang Template Range (for loop) using JSON from WebSocket
  • JSON-LD: Using data:post.body in Blogger template
  • com.google.android.gms.drive.DriveApi.ContentsResult cannot be resolved… But everything else can be?
  • Get webContentLink from google drive api with converted document
  • Get VS to highlight all .Net 3.5 SP1 method calls
  • View Controller Loads Twice - How Do I Fix It?
  • Should I create an object or work with an array?
  • In explicit LINQ-to-SQL (C#) does order matter?
  • Using a join with three tables when a field might be null
  • Bokeh custom ToolTips {safe} tag displays nothing
  • c# How to detect and process a .URL file type on DragDrop event
  • RxJava,Retrofit Error :Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
  • How to translate SQL queries to cypher in the optimal way?
  • Sequelize mssql: order by primary key and limit
  • Sorting table with just jquery, no other plugins
  • inserting items in list in mongodb document
  • Cannot invoke my method on the array type int[]
  • Oracle - Second level subquery cannot see field from main query
  • How to skip require in ruby?
  • Outlines on links in IE9 remains when focus is changed
  • Add dynamic data to line chart from mysql database with highcharts
  • Using Sax parsing to edit and write XML in VB6
  • Combining SpatialPolygonsDataFrame of two neighbour countries
  • Email verification using google app script and google forms
  • Cannot resolve symbol 'MyApi'
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Email format validation in mvc3 view
  • How to get address from latitude and longitude android google map v2 [duplicate]
  • Using $this when not in object context
  • Display issues when we change from one jquery mobile page to another in firefox
  • sending/ receiving email in Java
  • To display the title for the current loaction in map in iphone
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • trying to dynamically update Highchart column chart but series undefined
  • using HTMLImports.whenReady not working in chrome
  • How to stop GridView from loading again when I press back button?