The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December.
Read our blog post for more info about this change.
Found this content helpful? Log in or sign up to leave a like!
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.
Solved! Go to 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;
}
?>
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;
}
?>
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in