Have a question about the Canvas APIs? Have a cool API integration you'd be willing to share? If so, please post here.
Heiner Lieth , following up on what Gerald Q. Maguire has pointed you, you might also look at this document:
there is a variable that allows you to define the number of results you get per request: "per_page"
the defuault is 10, but you can reduce the number of api calls you have to make by increasing this number.
i use a default of 100 results.
I have been trying to wrap my head around this. In a Browser I can put in /api/v1/courses?per_page=1000 and I see that this seems to work to get all 26 courses. I purpose used such large number to avoid having to write pagination code as that would eat a few hours of my time. In my Visual Basic for Applications (VBA) project am using:
Dim Hreq As New WinHttpRequest
Hreq.Open "GET", URL, False Hreq.Send ResultStr = Hreq.ResponseText ResultHdr = Hreq.GetAllResponseHeaders
So that the last code line lets me inspect the header programmatically and I do find the Links there. But I see that when I use 1000 that it pages per 100. Perhaps 100 is the max allowed?
To clarify what Garth has said, I modified my earlier program to pass the additional parameter. See Listing your courses and paginated responses - more per page: Chip sandbox
I should note that there are some places in the Canvas user interface where the paginated responses are improperly handled by Canvas, see for example Changing limit on the number of custom columns shown by the GUI The result is that you do not get more than 10 custom columns shown in the gradebook even when there are more custom columns. (I'm still awaiting a response from someone at Instructure.com about this error.)
In my experience, 100 is the highest Canvas will return per page.
haven't tried any more than that, thanks : )
Heiner Lieth if i were you, i would invest the few hours and implement logic around pagination, it is the only way to guarantee you always get ALL results from any request. if you don't implement pagination, you could easily find yourself scratching your head wondering why you aren't getting everything.
just my 2 cents
You will need something like:
ResultLinks = Hreq.GetResponseHeader("Link")
then parse the resulting string (after a split on ";") for the current and last URLs, compare them; if not equal then loop with next URL
If you are using an SIS_ID, and since they are unique, it makes more sense for the middleware to target a user, not search for one: /api/v1/users/sis_user_id:firstname.lastname@example.org ....
... if that is an option for you.
I hope I am posting this question in the right place...
In the fall of 2015 I was trying to develop my own speedgrader for open response quiz questions when I discovered that the quiz API was not working as documented. This long process is covered in this thread that included Jason Sparks, James Jones and some key help from WIlliam Frakes.
In the end Jason Sparks said:
This is a very innovative use of the API. The current API remains in a beta stage as we are actively considering some new development on the quizzes front. For now there will not be any further development of the current API. We will share more in the near future as things progress.
17 months later I thought I would check back and see if any progress has been made. However, the documentation does NOT seem to have been updated - so the broken API calls and misleading examples (see my explanation) are still there.
Nevertheless, hope springs eternal and I wanted to see if someone from Instructure could provide an update.
Brookline High School
Building my first API - trying to pull the current user's first and last name for a printable certificate.
When I put the following url in a browser, it returns what I am looking for.
The above does not require my access token when used in the browser's address bar. But when I try and use PHP cURL it asks me to authenticate to pull that same URL. When I try and use our access token - it does not return the current user logged in, but rather my API user profile.
How do I use PHP cURL to get the current user's profile credential without authenticating?
Scoured the online documentation and sample scripts from Google without any luck. Thanks in advance for pointing me in the right direction.
I believe the answer is to form a GET request with the user ID in the URL endpoint
Users - Canvas LMS REST API Documentation
Oops forgot to mention that there's no way to get this information without being an authenticated user with proper permissions. You'd have to send an API token in the request.
You can also play with the api at Canvas Live API
Mitchell Gohman the api call you listed contains the parameter "self"
To quote the Canvas API documentation:
"Throughout this API, the :user_id parameter can be replaced with self as a shortcut for the id of the user accessing the API. For instance, users/:user_id/page_views can be accessed as users/self/page_viewsto access the current user's page views."
If you are logged in, you are the current user.
Take a look at the definition of the profile API call, it shows that it accepts the parameter of ":user_id":
You would need to pass the user id of the student you are trying to get information on.
You would also need necessary privileges to access that user profile, and I'm not sure what your role is.
From your post, it sounds as though you are trying to get information about students in a course.
If you are an instructor in the course you should be able to access your student roster, which also contains names, using this API call:
This API call returns a list of "User" objects:
In response to your statement: "The above does not require my access token when used in the browser's address bar", this is because you are already logged in with the browser. You absolutely need to use your own token when making API calls outside of the browser. If you need info on creating an access token, see this article:
If you would like more information on how to test and play around with API calls this post might be helpful:
I hope that helps.
First you need have your authorized user's access token. then in php, pass in your authorized tokenHeader, and pass as_user_id parameter to masquerade the userid who you are authorized to access the profile. e.g.
$asuser = array ('as_user_id' => $userid); $user = http_build_query($asuser, '', '&');
curl_setopt($ch, CURLOPT_URL, $canvasapiUrl' . '?'. $user);
Hopefully it helps.
Thank you Garth!! I think we are getting closer.
I saw the passing of the userID, but I am having trouble figuring out how to get the userID. Right now, my API application resides on a separate server (msmu.us)- not on our Canvas installation (msmu.instructure.com). Ultimately I would like to access the currently logged in user to get their details (already logged in through msmu.instructure.com).
I was successful in obtaining all of the students in the course, and passing an individual ID like the documentation says. But I need a way to tell which student is currently accessing the course. I think from what you are saying that this is not possible. That I would have to have them log into my application (using their Canvas Creds). Then I can do things for them specifically.
I would love it if the user only had to log into the main Canvas App once. And then my extended application would leverage this Canvas App login to perform user specific needs. Is this possible?
Or do I need to develop it as an LTI/Plugin in order to do this? Kind of like the Attendance App in Canvas, where it asks for permissions first. And it actually resides directly in Canvas, instead of an iFrame (which was my original goal) or a separate stand-alone website.
Thanks for all of your assistance and pointing me in the right direction.
If you know their sis id you can pass that in the form of 'sis_user_id:A000030483' .
Mitchell Gohman LTI would definitely tell you who the user is that is accessing your application.
I put together a 3 part LTI intro walk through that will help you get started in that direction.
Part1 is here: .NET LTI Project - Part 1 - Connect to Canvas
I also put together a list of helpful LTI resources: LTI 1.x - Useful Links
If you go the LTI route, take a look at these variables:
There is lots of info in the LTI launch request, should be everything you need to clearly identify the user, and if course specific will clearly identify the course they are launching your app from.
I'm currently working on extending the LTI posts to include the OAuth2 workflow, and have the first piece posted here:
.NET - OAuth2 Workflow: Part 1
Hopefully these references will be of some help, I'm working on part 2 of the OAuth2 example now and hope to have it posted soon (time permitting : )
Post back and let us know what direction you go in.
Got it, that is very helpful. Thank you for everything!!
Hey, as a part of a product requirement I need to add a link in each Canvas course to a predefined URL. In order to do so, I'm using the `external_tools` API in order to create them. I pass different values in the course_navigation param and a button is created at the bottom of the left navbar in the course navigation page. I'd like to place this button at the beginning of this navbar or, if it not possible, create the button in the left navbar of the course navigation (I've tried using the course_home_sub_navigation param but It didn't work). Any ideas? Thanks. Here is the doc I've been reading: External Tools - Canvas LMS REST API Documentation
Hello Everyone! I'm very new to APIs as well but I was wondering if It was possible to transfer grades from one course to another using an API? If so any tips on how to approach this?
@Raul Pineda You can certainly get the grades out of the gradebook with the API:
and you can insert grades for assignments (in the new course) with the API (I'll thanks @Peter Love for his posting Grade Change in Canvas API ):
You can see the whole process with some examples at https://kth.test.instructure.com/courses/11/pages/programs-related-to-assignments-and-their-grades
Your question was well timed, as I am just in the process of looking at how to bring over grades from another record system into Canvas (as students have done part of the requirements for courses prior to our introduction of Canvas) as our LMS. My hope is that moving the grades into the Canvas course will facilitate helping students to complete the remaining requirements of the course and hence finishing the whole course. You question prompted me to write my new tool: assign_grade_for_assignment.py course_id assignment_id user_id grade [comment]
The correct URL to use is: Programs related to assignments and their grades: Chip sandbox
as the one to the test environment will disappear (at some point).
The create assignment API
seems to create two duplicate assignments (instead of one) every time I call it. Has anyone else experienced this?
Welcome to the Canvas Community, Walter Yuan Welcome! Walter has also posted this as a separate question, so if you can help, please add your responses to Create assignment API creating duplicates
Retrieving data ...