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'm having some trouble with some development work for our classes using the Canvas API that is likely a beginner's issue.
The gist of the problem centers on my requests timing out. This could be a very newbie error, but it seems like my calls to the API (for current grade, missing assignments, last activity), bring in way more data that I need. I am not sure if this is what is slowing it down but it doesn't seem that I can even limit my calls to simply return the single fields I need (e.g. current_score). I use a Curl GET function that was posted here in the community a while back.
I am currently running PHP scripts via cron each morning. The load is about 40 classes and 600 students but I'm even at the point where I'm running 10 classes/150 students.
Any thoughts would be appreciated.
// The following function covers any API request using GET
function curlGet($url) {
global $canvasURL, $tokenHeader;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, 'https://' . $canvasURL . '/api/v1/' . $url);
// echo "https://$canvasURL/api/v1/$url";
curl_setopt ($ch, CURLOPT_HTTPHEADER, $tokenHeader);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // ask for results to be returned
curl_setopt($ch, CURLOPT_VERBOSE, 1); //Requires to load headers
curl_setopt($ch, CURLOPT_HEADER, 1); //Requires to load headers
$result = curl_exec($ch);
// var_dump($result);
#Parse header information from body response
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_size);
$body = substr($result, $header_size);
$data = json_decode($body);
curl_close($ch);
#Parse Link Information
$header_info = http_parse_headers($header);
if(isset($header_info['Link'])){
$links = explode(',', $header_info['Link']);
foreach ($links as $value) {
if (preg_match('/^\s*<(.*?)>;\s*rel="(.*?)"/', $value, $match)) {
$links[$match[2]] = $match[1];
}
}
}
Hi @lucas_ames ,
I am going through having a look at some of the early days in the Canvas Developers group, and checking in to see if older enquiries have been answered. I also noticed there hasn’t been any discussion on this question.
I am wondering, were you ever able to resolve this youorself? I am hoping I can assume that it is well and truly resolved by now, but if not, please let us know and we can certainly have another look. Alternatively, if have some insights you may be able to share for others that would be awesome too!
I will mark this as assumed answered for the time being, however, by all means please let us know if you still have an outstanding question and we will take a peek!
Cheers,
Stuart
I don't see any improvement on this, most of the calls have very very bulky returns, one of the more insane is the missing assignments object.
Some form of output selector would be a huge improvement, until that happens we face the same issues.
Hi @lucas_ames ,
Thanks so much for your follow up, if you log a feature idea for this at any point in the Canvas Studio space, feel free to come back and post it here, I am sure there are others that would be willing to vote on that, as I have seen it raised somewhere recently in addition to your post.
Hope that helps!
Stuart
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