Original Subject Line: How do I get Attendance Report using API (and not logging into Canvas through browser)?
What is the REST API call to get the attendance report for a class (or many classes) for a given time period ?
Message was edited by: Chris Hofer
Solved! Go to Solution.
I'm not aware of any REST API call that will return the attendance. It is an LTI application ran from rollcall.instructure.com and not native to your instance of Canvas, which is where the API works from.
If you're a teacher and only have access to your courses, then you can do the following:
Once you have launched it from Canvas, you can then visit https://rollcall.instructure.com/reports/new?course_id=#### (where #### is the same as your Canvas Course ID) and get a form that is used to start the report. You can fill it out the form and then click the Run Report button. Then it emails it to someone rather than providing it as an export. If you try to make the call directly from Canvas, then you get the warning "Please launch this tool from Canvas and then try again.", which is typical of LTIs.
One possibility would be to use a headless browser like PhantomJS or CasperJS to log into Canvas, launch the Attendance feature once from a class to make sure the LTI information is set, and then call the form and click on the button to generate the report. You could loop through the different courses that you needed to obtain the report for, or you could set it up with a command line parameter that took the Canvas course ID.
Of course, the reports are still emailed to the address you supply. Depending on your email system, you might be able to set up a script that automatically processes the email notification and then downloads the file using the supplied link. You have 24 hours from the time you generate the report to download it.
If you're an admin, then there is an Attendance navigation link from the Managed Accounts page.
You could can do much the same thing from there as I described above, and it might even be easier.
There is a specific URL that will take you to the the Export Attendance Data page. It's the one that you get when you click on the Attendance button. The export form loads in that page without having to mess with the attendance portion of Role Call that normally appears when you click on Attendance within a class setting.
It's still in an iFrame, though, because it is an LTI application.
However, CasperJS provides the withFrame() method that will allow you to switch to the iFrame where you can then fill out the form and submit it. PhantomJS has switchToFrame() that should accomplish that as well.
Note that if you go this route, you'll need to use the SIS Course ID rather than the Canvas Course ID.
The admin interface also allows you to get attendance for all courses, but only for a 7 day period. This means you could set up some kind of job that ran at least once a week and then combine each report together to get the attendance for all classes for an entire term (or however long you need).
If you have a lot of classes that are using the Attendance feature, it will probably be faster to piece it together this way (16 calls and get an entire semester vs 1 call for each class).