API to Unconclude a Course?

163 views
Skip to first unread message

Brandon @ Webster

unread,
Jan 13, 2014, 3:29:36 PM1/13/14
to canvas-l...@googlegroups.com
Has anyone found a way to unconclude a course using the API?

Rob Orton

unread,
Jan 13, 2014, 4:56:42 PM1/13/14
to canvas-l...@googlegroups.com
You should be able to edit a course and pass offer true.

This would only unconclude the course. You would also have to unconlude enrollments if you wanted that too.

-Rob

Brandon @ Webster

unread,
Jan 14, 2014, 10:33:20 AM1/14/14
to canvas-l...@googlegroups.com
I had initially tried that but the course wasn't unconcluding so I wasn't sure if there was another way to do it, or I just had some errors in my code...

Here's what I go going at the moment:
$url = $domain . '/api/v1/courses/' . $course_id;
$fields = array(
"course[end_at]" => "",
"offer" => "true"
);
$fields_string = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$access_token));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
$data = json_decode(curl_exec($ch),true);
print("<pre>".print_r($data,true)."</pre>");

which returns the following result:
Array
(
    [account_id] => (account id)
    [course_code] => BKDEV
    [default_view] => syllabus
    [id] => (course id)
    [name] => Brandon's Dev
    [start_at] => 2013-08-09T17:36:51Z
    [end_at] => 
    [public_syllabus] => 
    [storage_quota_mb] => 500
    [hide_final_grades] => 
    [apply_assignment_group_weights] => 
    [calendar] => Array
        (
            [ics] => (calendar url)
        )

    [sis_course_id] => 
    [workflow_state] => completed
)


Now, I was able to unconclude the course using https://canvas.instructure.com/doc/api/courses.html#method.courses.batch_update using the following:
$url = $domain . '/api/v1/accounts/' . $account_id . '/courses';
$fields = array(
"course_ids[]" => $course_id,
"event" => "offer"
);
$fields_string = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$access_token));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
$data = json_decode(curl_exec($ch),true);
print("<pre>".print_r($data,true)."</pre>");

so at least there is a workaround on the off chance the update course > offer endpoint is broken
Reply all
Reply to author
Forward
0 new messages