cancel
Showing results for 
Search instead for 
Did you mean: 
raodm
Community Participant

How to determine Assignment number from LTI call?

Jump to solution

Hello,

I am trying to figure out how to determine the assignment number (that is, :id value in API call further on) from a Canvas LTI call (associated with assignment submission) so that I can get more information about the assignment (via GET /api/v1/courses/:course_id/assignments/:id ).  I do get a bunch of POST parameters passed to my tool from Canvas shown below. Is there a Canvas API can that convert one of the id's (say resource_link_id for example) to an assignment number?

Here are some of the POST parameters for example:

oauth_consumer_key=007 
oauth_signature_method=HMAC-SHA1
oauth_timestamp=1466800526
oauth_nonce=REfacGPKBkwPGOkxxigATdLnMfq96QrFfjX1KAB2U
oauth_version=1.0
context_id=5652d0ea668c8394bbad9a217be93cb6f8fee83b
resource_link_id=ab0781f4e77d18a9c4c832190954e1337ddd7574
user_id=3e0dfbe0931773757ad68de7ebcd6005e859cdb1
oauth_signature=DCXH0eD60s2EpNVNM/hy0uvanlg=
...
1 Solution

Accepted Solutions
raodm
Community Participant

I resolved my issue. My immediate problem is solved! However, I am still unsure about the relationship between <blti:launch_url> and <lticm:property name="url">.  Do they need to be the same or can they be different? If they are different it does not work as expected. Is that a Canvas bug or a feature?

In any event, here is more information on how I went about troubleshooting my issue -- hopefully it is of some use to others who may experience similar issues.

You've gotta love open source code base. As always, digging through the source code (at canvas-lms/tool_launch.rb at stable · instructure/canvas-lms · GitHub ) gave me good hints for troubleshooting. As I guessed earlier, the issue was with my XML configuration file. Here is the first clue I got from the source code (copy-paste from tool_lauch.rb😞

def add_assignment_substitutions!(assignment)     
    if tool.public?
         hash['custom_canvas_assignment_id'] = '$Canvas.assignment.id'
    end
    hash['custom_canvas_assignment_title'] = '$Canvas.assignment.title'
    hash['custom_canvas_assignment_points_possible'] = '$Canvas.assignment.pointsPossible'     end

I had my privacy level set to name instead of public. Changed that in my XML as in:

<lticm:property name="privacy_level">public</lticm:property>

That change alone did not fix my missing parameter issue. Reviewing the code more, my eye caught the following check:

     if context.is_a?(LTICourse)
           hash['custom_canvas_course_id'] = '$Canvas.course.id'
           hash['lis_course_offering_sourcedid'] = '$CourseSection.sourcedId'
 

That got me thinking if there is some dependency on tool and options URLs etc. So I changed by URL to be consistent throughout my XML configuration, that is, I ensured that:

 <blti:launch_url>https://code.cec.blah.edu/code/code.php</blti:launch_url>

matched with

    <lticm:options name="homework_submission">
         <lticm:property name="url">https://code.cec.blah.edu/code/code.php</lticm:property>

Once I did those two changes, Viola! The magic/mystery parameters custom_canvas_assignment_id custom_canvas_course_id etc. (that were mentioned by  @RobDitto  and  @garth  in this conversation) showed up consistently and correctly in both Instructor and Test Student views.

View solution in original post

14 Replies
kona
Community Coach
Community Coach

 @raodm ​, because of the technical nature of this question I'm going to share it with the Canvas Developers​ group in the community to see if they can help!

garth
Community Champion

You did not list all of the oAuth params, so I'm going to assume you have all of them.

  • lis_outcome_service_url - this is the post back url, the API endpoint you will call to pass the grade
  • lis_result_sourcedid - this is the unique identifier of the assignment you want to grade

The grade you post back is coming from your app, and must be a decimal, i.e. an 80% should be passed back as 0.8

When Canvas launches your LTI assignment, Canvas will pass a group of lis_* parameters in the oAuth header.

You need to store those on your end, then when you post the grade back, use those parameters to post the grade to the proper assignment/user.  That's where the two variables I listed come into play.  lis_result_sourceid represents the unique coures/user/assignment/submission, ensuring the grade is properly assigned in the gradebook.

Let me know if this get's you over the hump.

RobDitto
Community Champion

For an External Tool assignment, the name of the LTI form POST parameter will be custom_canvas_assignment_id. Its value will be that assignment's ID at the end of its URL in Canvas, as well as the :id in your GET API call.

raodm
Community Participant

Unfortunately, Canvas does not seem to include the lis_result_sourcedid oAuth configuration parameter in the call for me. Could this be an issue with the way I have my configuration XML file setup for my tool (associated with assignment submission)?

raodm
Community Participant

Unfortunately, I don't seem to be getting the custom_canvas_assignment_id as part of the POST request parameter from Canvas. Here are the only 3 custom_* parameters that I do get:

custom_canvas_assignment_points_possible=10
custom_canvas_assignment_title=Test Assignment
custom_canvas_enrollment_state=active
garth
Community Champion

 @RobDitto ​, you are correct, I goofed, sorry, the parameters are coming from the Form data.  I should know better than to speak from memory : )

 @raodm ​, let's make sure we are talking about the same thing.  When I create a new assignment in Canvas, for "Submission Type" I select "External Tool" and point it at my LTI app.  When the student clicks on the assignment, Canvas loads the assignment from my server.  Is this the type of assignment you are talking about?

submission-type.png

One thing to keep in mind, the parameter that Rob is talking about: custom_canvas_assignment_id, is specific to Canvas

The lis_result_sourcedid is compatible with all LTI compatible platforms.  At least that is my understanding.

So if you plan to use your LTI on another LMS platform, you will want to use the lis_* parameters.

Here is a full list of parameters that I receive from the Form data when Canvas loads my LTI assignment:

"oauth_consumer_key"

"oauth_signature_method"

"oauth_timestamp"

"oauth_nonce"

"oauth_version"

"context_id"

"context_label"

"context_title"

"custom_canvas_api_domain"

"custom_canvas_assignment_id"

"custom_canvas_assignment_points_possible"

"custom_canvas_assignment_title"

"custom_canvas_course_id"

"custom_canvas_enrollment_state"

"custom_canvas_user_id"

"custom_canvas_user_login_id"

"ext_ims_lis_basic_outcome_url"

"ext_outcome_data_values_accepted"

"ext_outcome_result_total_score_accepted"

"ext_outcomes_tool_placement_url"

"ext_roles"

"launch_presentation_document_target"

"launch_presentation_locale"

"launch_presentation_return_url"

"lis_outcome_service_url"

"lis_person_contact_email_primary"

"lis_person_name_family"

"lis_person_name_full"

"lis_person_name_given"

"lis_result_sourcedid"

"lti_message_type"

"lti_version"

"oauth_callback"

"resource_link_id"

"resource_link_title"

"roles"

"tool_consumer_info_product_family_code"

"tool_consumer_info_version"

"tool_consumer_instance_contact_email"

"tool_consumer_instance_guid"

"tool_consumer_instance_name"

"user_id"

"user_image"

"oauth_signature"

raodm
Community Participant

OK, this is interesting -- I switched to "Student View" in Canvas, and with the "Student View" I do get lis_result_sourcedid as shown below (I would have to guess what those numbers correspond to next):

lis_result_sourcedid=4221-27332-223835-68417-c2e7f9e56e9db3fa5cc3ef5de2c80fc25683f5ca

So, why don't I get that parameter as the "Instructor" of the same course?

garth
Community Champion

That sounds right.  As a teacher, you do not have an assignment submission for grading.  You need to be a student in order to submit work.  Hopefully you are over the hump : )

raodm
Community Participant

 @garth ​ Yes, I have exactly the LTI setup you described.

However, neither in the "Student View" or as "Instructor" I get the "custom_canvas_assignment_id" parameter (and a few more) you have listed above. However, I would like to get them.