Hi,
I have done this via the API. I had a csv file of the course ids, and one by one via a php script I called /api/v1/courses/:course_id/settings with restrict_student_past_view=true. See https://canvas.instructure.com/doc/api/courses.html#method.courses.update_settings for details.
The PHP code snippet looked like this:
$courses = file('courses.csv', FILE_SKIP_EMPTY_LINES);
unset($courses[0]); //first line has a header row, not an id to process
foreach ($courses as $course) {
$course = trim($course);
$url = "courses/sis_course_id:$course/settings";
$json = "restrict_student_past_view=true";
$response = $api->curlPut($url, $json);
}The curlPut method is from code I found in the community here and rewrote as a class method. It looks like this:
function curlPut($url, $data){
$data = trim($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$this->canvasDomain.'/api/v1/'.$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->tokenHeader);
curl_setopt($ch, CURLOPT_SSLVERSION, 6); //Force requsts to use TLS 1.2
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // ask for results to be returned
// Send to remote and return data to caller.
$response = curl_exec($ch);
curl_close($ch);
return $response;
}The construct method for this class contains our Canvas domain, an access token and creates the token header: $this->tokenHeader = array("Authorization: Bearer ".$this->token);
It all worked earlier this year when I did this. There might be a more efficient way to do this, but this ought to work.
-S