cancel
Showing results for 
Search instead for 
Did you mean: 
jbritschgi
Community Member

Adding default course cards.

Jump to solution

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 Kudos
1 Solution

Accepted Solutions

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 Kudos
2 Replies
JamesSekcienski
Community Participant

Are you able to share the code you are using to perform the update?

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 Kudos