cancel
Showing results for 
Search instead for 
Did you mean: 
nschutz
Adventurer

Sync Blueprint courses via API

Jump to solution

Recently we made a across the board change to all the blueprint courses and therefore need to trigger the unsynced changes so the associated courses get updated as well. The API is provided to do that and I tested it successfully in Postman, updating 1 course at a time.

POST /api/v1/courses/:course_id/blueprint_templates/:template_id/migrations

However, when I have to run this for all the blueprint courses, it only executed a few courses at a time as if there were a limit enforced somewhere. I increased the timeout value from 30 to 600 and still only the same number of courses were synced. Does anyone know where the limit comes from? How to increase it? or how to work around this so I can run the script once for all the 100+ blueprint courses?

Below is my PHP code snippet.

<?php
// this page will run force sync on the supplied blueprint courses.
$courseIDs = array(xxx, xxx, xxx); //the array contains over 100 course ids
$length = count($courseIDs);
for($i = 0; $i < $length; ++$i) {
    $cid = $courseIDs[$i];
    $postURL = "domainurl" . $cid . "/blueprint_templates/default/migrations";
    $curl = curl_init();

    curl_setopt_array($curl, array(
      CURLOPT_URL => $postURL,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 600, //increased from 30
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_HTTPHEADER => array(
        "Authorization: Bearer xxxxx
        "Cache-Control: no-cache",
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

}
?>

Labels (1)
0 Kudos
1 Solution

Accepted Solutions
nschutz
Adventurer

I figured out why only the first few requests were processed. It was a default setting in the php.ini file of max_execution_time=30, which limits the running time of the script to 30 seconds. I changed that value and restarted my server and all requests went through.

View solution in original post

1 Reply
nschutz
Adventurer

I figured out why only the first few requests were processed. It was a default setting in the php.ini file of max_execution_time=30, which limits the running time of the script to 30 seconds. I changed that value and restarted my server and all requests went through.

View solution in original post