harvard-edtech / caccl

The Canvas App Complete Connection Library (CACCL) is an all-in-one library for building Canvas-integrated apps. By handling LTI, authorization, and api for you, CACCL makes building Canvas-integrated tools quick and easy. Keywords: Canvas LMS Instructure API LTI Authorization EdTech Education
MIT License
33 stars 4 forks source link

Course context #10

Closed kevincolten closed 3 years ago

kevincolten commented 3 years ago

@gabeabrams

How do you grab the context for what course you open the LTI in? In the examples, you are passing in an arbitrary course id:

app.get('/student-names', async (req, res) => {
  if (!req.api) {
    return res.send('Oops! You are not authorized.');
  }

  const students = await req.api.course.listStudents({ courseId: 58320 });

  const names = students.map(x => x.name).join(', ');

  return res.send(`Here are all your student's names: ${names}`);
});
gabeabrams commented 3 years ago

@kevincolten, great to meet you!

CACCL automatically adds all the launch info to the user's session. For a full list of parameters, check out these docs and scroll down to the section on "Launch Parsing": https://github.com/harvard-edtech/caccl-lti

The value you're looking for is courseId. So on the server, that is accessible as follows:

app.get('/student-names', async (req, res) => {
  ...
  const students = await req.api.course.listStudents({ courseId: req.session.launchInfo.courseId });
  ...
});

For reference, this is all in the CACCL docs bit.ly/caccl in the server-side section with subheading "Get Info on Status, Auth, and LTI Launch"


If you're building a react app and need the courseId on the client, visit the CACCL docs bit.ly/caccl and find the client-side section with subheading "Get Info on Status, Auth, and LTI Launch" which walks you through how to get that launchInfo object on the client.

And if you're having any trouble with any of this, please let me know! I'm happy to help!