Edit group membership via API

dagray3
Community Member

I'm working to create a tool to allow for editing group membership by importing data from a spreadsheet.  I form my teams using external tools, and then I have to manually drag and drop multiple hundred students into individual teams using the Canvas UI.

I'm using the API GET, POST, and PUT commands using a Javascript interface.  I'm working in a Google Apps Script bound to a Google Sheets spreadsheet.  I want to make a template tool to distribute to my peers where they can import their roster, and then click a button to import the teams to their Canvas site.

I have my tool in a state where I can 

  • check is the Group Set exists and if not, create it
  • check if the group names exist within the group set, and if not create them

I cannot seem to get the API PUT to edit the group members to work, no matter what I try.

My current exists as a function.  I generate a list of group names, and a list of students for each group.  I use a GET call to determine the groupID for each group in the Canvas site.  My main code then calls the populateGroup function with the groupID (pulled from the GET call) and the list of students (collected from the spreadsheet).  My current code is 

--------------------------------------------------------------------------

function populateGroups (groupID,students){
var data = {"members":students};//students is a list of student IDs from another function
var headers = {"Authorization": "Bearer " +token}
var options = {
"method":"PUT",
"headers":headers,
"payload":data,
"muteHttpExceptions" : true
}

//populate group via API PUT
var result = UrlFetchApp.fetch('https://canvas.vt.edu/api/v1/groups/'+groupID,options)
var response = result.getContentText();
var res_code = result.getResponseCode();
}

----------------------------------------------------------------------------------

I've tried a bunch of different things and I keep getting a 404 Error "The specified resource does not exist."

I can't seem to get the PUT request

PUT /api/v1/groups/:group_id

 

to work with anything I try.  I've tried changing the payload to

  • 'members'
  • "members"
  • 'members []'
  • 'members[]'

I've tried stringifying the payload (with a 'content-type': 'application/json' in the headers).

I've tried changing the group name using this command rather than editing the team memberships, and I can't get anything to work.

I have also tried changing what I use to identify the students;

  • Canvas ID
  • SISID
  • pid
  • email
  • name

Does anyone have any suggestions on what I'm doing wrong?