cancel
Showing results for 
Search instead for 
Did you mean: 
jacob_anavisca
Surveyor II

How to get users canvas id through LTI without them interacting with the LTI

The use case is to use the Canvas Live Events webhook to get event information (like a assignment change for multiple students) and then send a notification to the users that it relates to. We would need to determine Canvas user IDs for the students affected by the change. We are a third-party service and so we would not be storing any data. We do use OAuth and the REST API for another part of our service but there would be no way to let our webhook know what the canvas IDs are. I thought we could get the IDs by making a request as an LTI to the names_and_roles endpoint. When making a request to the names_and_roles endpoint it'll return students like so:

{
            "status": "Active",
            "name": "Jacob Anavisca",
            "picture": "https://canvas.instructure.com/images/messages/avatar-50.png",
            "given_name": "Jacob",
            "family_name": "",
            "email": "jacob.anavisca@modolabs.com",
            "user_id": "953c289a-d8fa-4975-afe3-5345658c3ae2",
            "lti11_legacy_user_id": "1742003b58de4342d9264dced2c8ae3c7e57cc61",
            "roles": [
                "http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor"
            ]
        }

 

The user_id and lti11_legacy_user_id do not match the actual canvas IDs. This LTI was only set up in order to get the Canvas IDs so students do not interact with it, no launching. Is there any way to get the actual Canvas ID?

Labels (2)
0 Kudos
3 Replies
matthew_buckett
Adventurer II

It's a while since I looked at this but I think if you add a custom parameter to your LTI Developer Key so that you ask Canvas to pass through the native Canvas User ID using something like:

canvas_user_id=${Canvas.user.id}

Then I think in your names and roles request you should get a custom claim for each user that includes their canvas user ID under the field `canvas_user_id`.

https://canvas.instructure.com/doc/api/file.tools_variable_substitutions.html

I just tried adding that custom claim as well as a few others but the response is still the same. I read through https://canvas.instructure.com/doc/api/file.tools_variable_substitutions.html and it seems as the user would have to launch the LTI for substitutions to show up in the response. This isn't going to work for us, unfortunately.

matthew_buckett
Adventurer II

I've just had a look and when using the Names and Roles service (https://canvas.instructure.com/doc/api/names_and_role.html) and the tool registration has custom variable expansions I also get those variables for each user returned. Here's a snippet of the response I get back on one of our tools:

{
  "id" : "https://canvas.ox.ac.uk/api/lti/courses/75998/names_and_roles?rlid=a71fc33bece353a82d335d92931cd70fbfa8eec7&per_page=100",
  "context" : {
    "id" : "a71fc33bece353a82d335d92931cd70fbfa8eec7",
    "label" : "EMT-001",
    "title" : "Export Member Test"
  },
  "members" : [ {
    "status" : "Active",
    "name" : "Matthew Buckett",
    "picture" : "https://secure.gravatar.com/avatar/2af16812634729f02aefa45e87028341?s=128&d=identicon",
    "given_name" : "Matthew",
    "family_name" : "Buckett",
    "email" : "matthew.buckett@it.ox.ac.uk",
    "user_id" : "39d7838d-9784-4b7a-b438-04fc0155d4dd",
    "lti11_legacy_user_id" : "5de1538afb8f1cab07a03c891df215badaa4d7f7",
    "roles" : [ "http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor" ],
    "message" : [ {
      "https://purl.imsglobal.org/spec/lti/claim/message_type" : "LtiResourceLinkRequest",
      "locale" : "en-GB",
      "https://purl.imsglobal.org/spec/lti/claim/custom" : {
        "canvas_user_id" : 2,
        "canvas_user_login_id" : "buckett@ox.ac.uk",
        "canvas_user_sis_source_id" : null,
        "canvas_user_sis_integration_id" : null,
        "canvas_user_prefer_high_contrast" : "$Canvas.user.prefersHighContrast",
        "com_instructure_brand_config_json_url" : "$com.instructure.brandConfigJSON.url"
      },
      "https://purl.imsglobal.org/spec/lti/claim/lti11_legacy_user_id" : "5de1538afb8f1cab07a03c891df215badaa4d7f7",
      "https://purl.imsglobal.org/spec/lti/claim/lti1p1" : {
        "user_id" : "5de1538afb8f1cab07a03c891df215badaa4d7f7"
      }
    } ]
  }]
}