Rubric re-linking to discussion

Jump to solution
Nva2023
Community Explorer

Hello All and  @James 😁

Currently, we have discussions with various old rubrics attached. 

Now, the new rubric needs to be re-attached to each discussion. 

Based on this link, https://canvas.instructure.com/doc/api/rubrics.html 

As I understand, we need to call; is it correct? PUT /api/v1/courses/:course_id/rubric_associations/:id

To GET all rubric_associations to the practical discussions? I think it's this one, GET /api/v1/accounts/:account_id/rubrics/:id - but this allows you to look up by a rubricID.

Some discussion boards have different rubrics attached, and we need to link this new rubric to them. 

To sum up, with API - How can I update the new rubric under all discussions without lookup the old rubric ID and rubric_associations? is it possible?

Please guide me with the appropriate calls. 😀

Labels (1)
0 Likes
2 Solutions
James
Community Champion

@Nva2023 

Strangely enough, when I got your message, I was involved in adding rubrics to discussions.

First, depending on how many discussions you have, it may be easier to do this through the web interface. That said, let's look at how to do it through the API.

First, I'm not 100% positive you want the PUT version of the API request.

When I'm not sure how to do something, I open up the browser developer tools in Chrome and look at what Canvas sends. I took a discussion that had no rubric and found one and it did a POST. That would be expected since it was a new association. But then I took that same discussion and changed the rubric and it still did a POST.

So you can follow, my course is 3646256, my discussion ID is 21599627, the corresponding assignment ID is 40075233.

It made a POST to courses/3646256/rubric_associations

The payload was

rubric_association[association_type]: Assignment
rubric_association[association_id]: 40075233
rubric_association[rubric_id]: 3402530
rubric_association[purpose]: grading
_method: POST

 

First, notice that is not an API call, it's a call to an internal routine not exposed through the API. Sometimes they are similar, but often they have extra functionality that is not exposed. That's why I'm not sure you need a PUT, if you're using the API version, you might need a PUT, but I would start with a POST. What might be happening behind the scenes is that the routines make a call to lookup any existing id and then do the put.

To test what is needed, I tried to update another discussion's rubric through the API. This discussion id is 21599630 and the associated assignment id is 40075236.

I made a POST /api/v1/courses/3646256/rubric_associations with this payload (as JSON).

{
  "rubric_association": {
    "rubric_id": 3402530,
    "association_id": 40075236,
    "association_type": "Assignment",
    "purpose": "grading",
    "use_for_grading": true
  }
}

It even checked the "Use for grading" box for me, which was a timesaver. You could leave that off if you wanted to.

You will need the rubric_id 3402530.

The easiest way is to go to the Rubrics page within the course and mouse over the rubric you want to use. When I do that, I get a pathname of /courses/3646256/rubrics/3402530

The ending number is the rubric I want to use.

But we're talking about how to do it through the API.

If you call GET /api/v1/courses/3646256/rubrics then you will get a list of all of the rubrics for the course.  It gives you an array. I would search for the title and then take the id of the matching one. That's the rubric_id that you're looking for. It's not called rubric_id, it's called id but it is the id of the rubric object, which makes it the rubric_id everywhere else.

Putting that all together, I would

  1. Get the ID of the rubric you want to use -- either through the API or web interface.
  2. Look up the discussions using the List discussion topics endpoint. Each of these will include an assignment_id property, provided that the rubric is used for grading.
  3. For each of those assignment_id that you found, make a call to Create a rubricAssociation as explained above.

It took me using 2 of the 5 discussions I needed to add a rubric association to in order to figure things out. Now that I have the command in my REST client, I'll just ago ahead and finish the rest with the API.

There is one potential issue with this. My discussion assignments were all worth 10 points, but my rubric was worth 10.5 points to allow a little extra credit. Using the API reset the point values on the assignments. Now I have to go back and reset the points. To do that through the API, Canvas updated the Rubric with skip_updating_points_possible=true, but that needed an existing association ID, which you're trying to avoid finding. Hopefully you won't run into that issue.

View solution in original post

James
Community Champion

@Nva2023 

I don't know about the library you're using, so I'll focus on the material.

Your JSON looks malformed. It is not an array, it's an object with a property of rubric_association that contains the object you have. Take a look at the second code block example I gave.

If your library doesn't send a content-type: application/json, you should add it when you send a JSON body.

View solution in original post

0 Likes