Celebrate Excellence in Education: Nominate Outstanding Educators by April 15!
Found this content helpful? Log in or sign up to leave a like!
What is the quickest way (via API) to tell whether any content has been created in a given course? (meaning *any* type, and not a particular type of content). I am aware of the 'unused' account report type, and could probably use this lacking a better alternative. I'd consider acceptable a solution that requires 1 API request per course, but not more. It would be great to hear if anybody has come up with a different answer for this question.
By "quickest way" do you mean the fastest to write or the fastest to execute? Also, you say that you want to check content in a "given course" but then you talk about 1 API call per course, which makes it sound like you want a list of all the courses that are unused.
I'm going to answer it like you want a list of courses, not just to check whether one course is unused or not.
There is only one API call that I know of that will meet your requirements of no more than one API call per course. That's the API call that generates the unused_courses report. You can throw in a call to get a list of reports and one to check the progress, which might need to be made multiple times if you're really impatient, but that's still just 3 calls for all of your courses.
Your requirement that you're going to do this with just 1 call per course mostly fantasy. Reports run in the background because they take some time to process and you cannot expect immediate results. On the other hand, API calls are made to come back quickly so that the application making them doesn't have to wait or the connection be held open for the minutes (maybe longer if things the servers are busy).
The unused_courses report involves finding courses that have no assignments, no files, no discussions, no modules, no quizzes, and no content pages. Each of those has its own controller in Canvas, which means there's an API call for each of them. That's 6 API calls per course.
There is one other possibility, but someone who understands it better than me will have to chime in. That's GraphQL. This is what Canvas uses to do the new analytics and for the user cards from the roster page. GraphQL can pull data from multiple sources. The legacyNode and node items have all of those things under them, I just don't know how to connect them all together and then make it work with allCourses. Or if it even will?
For example, from the legacyNode courses class, there are connectors for assignment groups, assignments, grading periods, group sets, groups, modules, sections, submissions, and users. In my limited playing around, that means you can connect those together, but it leaves out discussions, quizzes, and content pages. Most discussions and quizzes will appear under assignments ... as long as they're graded, but my practice quiz for the final doesn't get included.
There's also a node class with some connections, but it also looks to be missing some of the connectors needed to tie all of the information together. This makes sense; if connectors existed for everything, then you would basically have free reign on the database and could write some really bad queries that killed performance.
There's no documentation on Canvas' implementation of GraphQL, but it was demonstrated to a technical audience at the 2018 InstructureCon. At the presentation, the Canvas engineers didn't quite consider it ready for prime time.
Thanks James for replying. I actually did *not* mean that I want a list of all courses that satisfy that (otherwise I'd take the 'unused courses' report, which both of us mentioned in our posts). Yes, I also remember the GraphQL alternative API being mentioned as being in progress at InstructureCon. As you said, I imagine this is not yet ready for prime time (thanks for reminding me about it). My use case is that I'd have to figure out (a yes/no answer for my question) for a few courses at a time. I was trying to avoid making those 6 API calls per course (as I may have perhaps 10 at a time, although in average fewer), while also avoid the wait time that the report would involve. But it's sounding like those may be the two options available...
Always interjecting with... do you have Canvas Data?
This can be pretty simple query with if you want to look at courses and join to pages, assignments, quizzes, discussions etc... NULL counts are unused courses.
I didn't mention that just because she said API, but yes, that would be the quickest way if it was available. But it would be delayed and so you wouldn't want to automatically delete any course that Canvas Data flagged without checking it another way, which is where the 6 API calls would come in.
If you're only wanting the information for 10 courses at a time, definitely make the 6 API calls.
If you use an asynchronous programming language (e.g., JavaScript) instead of a synchronous one (e.g., PHP), then you can make all 6 requests at one time and still get all the results in less than a second. I average about 10 API calls per second when I fetch nightly updates -- that's with me throttling to make sure I don't exceed the limits.
You're only talking 6-10 seconds to get the results.
Thanks James and Robert for replying. Yes, the 6 api calls are the way to go if we're using the API, as we want real-time results. Sorry I didn't see your replies earlier (for some reason, I'm not getting notified when there are replies to my posts, which seems to be a bug :-().
Yes, I have done this already. Thanks again
To participate in the Instructure Community, you need to sign up or log in:
Sign In