Adding default course cards.

Jump to solution
jbritschgi
Community Member

I have written a php script for generating course card images so my institution's courses can have individualized cards.  I have placed these out on a web server and am trying to update the courses by adding course[image_url] via /v1/courses/{id}

This works when I do so for an individual course, but when I try looping through a list of courses, it only updates the first course on the list even though I can see that the loop is executing.

0 Likes
1 Solution

Sorry, I guess including the code would help.  And actually I deleted the code last night and rewrote it from the ground up, so now it works.  Here is the working code:

<?php
$handle = fopen("courses.csv", "r");

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {



$URL = "https://somecollege.instructure.com:443/api/v1/courses/".$data[0]."?course%5Bimage_url%5D=https://somesite.edu/media/images/canvas/".$data[3].".png";
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => $URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer HaHaYouThoughtIWouldIncludeThis'
),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
}


?>

View solution in original post

0 Likes