Found this content helpful? Log in or sign up to leave a like!

Canvas LMS API for New Quizzes - points_possible endpoint

scott_whitney1
Community Explorer

I desperately need a bulk editor for New Quizzes. I'm working on creating one that works with Google Sheets. However, I have not been able to figure out how to get the New Quizzes points_possible for each quiz. I can easily get the assignment points_possible, but New Quizzes has it's own points data and the two points_possible values  don't match for me because I originally imported them as practice quizzes which have an assignment point total of 0. I want to fix that. In Google sheets, it would be easy to copy the New Quizzes points_possible and paste to the associated assignment points_possible, but so far I'm hitting a roadblock.

The only approach I can think of is to first retrieve the list of assignments which are actually New Quizzes. Then open each one and retrieve the items. Then go through each item and get the points_possible and sum them up.

I already have the assignment IDs correctly written in Google Sheets, so it's a matter of getting the New Quiz data.

Step 1:

var itemsData = canvasAPI(
      'GET /api/quiz/v1/courses/:course_id/quizzes/:assignment_id/items',
      { ':course_id': courseId, ':assignment_id': assignmentId }
    );
At this point, I'm making educated guesses as to how to access each item:
Step 3:
items = itemsData.items
Step 4: 
// Sum up points_possible (defensively coerce to number)
    var total = items.reduce(function(sum, item) {
      var p = 0;
      if (item && typeof item === 'object') {
        p = item.points_possible || item.points || 0;
      } else if (typeof item === 'number') {
        p = item;
      }
      p = (typeof p === 'string') ? parseFloat(p) : p;
      if (isNaN(p)) p = 0;
      return sum + p;
    }, 0);

    return total;
 
My questions:
Is there anything obviously wrong with my approach?
Do I have any incorrect endpoints in the request?
Am I using the correct approach with items = itemsData.items?
 
0 Likes