Have a question about the Canvas APIs? Have a cool API integration you'd be willing to share? If so, please post here.
Hi, I am completely new to this. I am actually an Admin for our institution and not a developer but I would like to learn some basics about APIs. Could you recommend some introductory material I can review to understand them better? Thank you in advance!
I have a developer key, and I'm trying to nail down my workflow for collecting/updating tokens. One thing I am doing is testing the validity of an existing token so that I can initiate a new token request if the one in my db has expired or been deleted. I couldn't find any direct way to do this, so I am making a GET request, and looking to see if it fails. When I initially set this up, I was getting a return array with $response['status']="unauthorized" or "unauthenticated" when the token failed. At some point, that changed, and now I have to look for $response['errors'][0]['message']=="Invalid access token."
So, I guess my question is, what is the preferred way to test a token? Is there something I can count on not to change out from under me in the future? If it matters, I'm using PHP and cURL.
Hi Scott,
I am developing a Ruby on Rails app for the creation and curation of math problems (LaTeX, Desmos graphs), and trying to wrap my head around using the API to interact with our Canvas instance to create quizzes, etc. I am new to this group, so please let me know if there are threads I should read before reinventing the wheel here. A few questions to get started:
(1) Which rubygem is recommended for interfacing with the Canvas API? My plan is to use pandarus (instructure/pandarus · GitHub ) but I am open to suggestions. I also started tinkering with canvas-api (whitmer/canvas-api · GitHub ).
(2) Assuming that pandarus is the way to go, it appears to me that the gem requires knowing a user's access token in order to use the API calls (which makes perfect sense).
client = Pandarus::Client.new(
prefix: "https://pandamonium.instructure.com/api",
token: "[YOUR API TOKEN HERE]")
But what is the interface to first retrieve the user token given the app's "client_id" and "secret"? Does pandarus provide an interface for this, or should I use something like httparty for the so-called "OAuth dance"?
(3) In terms of the API itself, how can I link or embed a picture/graph within a quiz question? I see that the API allows for creation of questions and answers, and the uploading of files. But how can I then link the two from my app? I could not find an option in the doc to do this.
(4) Related to the question above, is it possible to embed/link graphs in answers as opposed to questions? We would like to have math problems offer graphs as solutions.
Hope these questions make sense. Apologies in advance if these are really noob'ish, but I am just getting started with the API work.
Best,
-Jacques
What's the best way to let Instructure know about a bug (or something that appears to me to be a bug) in the API? I have been experimenting with creating quizzes, which means using parts of the API that are still in beta. I want to report bugs as I find them, not because I expect them to be fixed right away but just in case the information is helpful to developers.
I've submitted a few tickets through the general Canvas help center, but that means extra work for the admin people at my institution (who filter tickets so that Instructure only gets what seem like genuine errors). It seems like it would create extra work for Instructure also, although I don't really know how many steps are involved in getting from support techs to developers.
I just learned the most amazing thing, right here in the community, but hidden away in a questions page. I'm thinking we should have a place to collect a list of undocumented admin/developer gems. Ever hear of /undelete? Do you know of others?
I am using PHP cUrl with the Canvas API to create quizzes and add quiz questions. Canvas LMS REST API Documentation shows the API call necessary for question creation. Creating the question works as long as I do not include an answer. The API requires question[answers] with [Answer] as in input. I have tried multiple arrays with various names for the keys. Does anyone have a working example of adding a quiz question with answer, or adding an answer to an existing question?
I use the api via the Pandurus gem. Based on a faculty request feed from another app I use content migrate to pull in a template course. This is then completed by creating modules for the varying number of weeks. Some of the pages also have their content modified by pulling them and doing a regex for things like course and faculty names. Since our enrollment feed does not include course drops I use the api to compare the courses section enrollments with the actual enrollment data. That data is used to generate an SIS file to conclude the students that have left the course. Since that last one is a bit api intensive it only runs once a day. I also use the api to upload the hourly full SIS package that is created by the app.
Hi all! I work at the London campus of Hult International Business School. We've developed a small command-line utility to automate a few tasks in Canvas, especially when dealing with groups. We'd love to share it with other institutions or get some feedback from developers about it!
https://github.com/jasongwartz/CanvasHelper
Now we have the professors fill out a simple spreadsheet and use this tool to create all the student groups in a course automatically. It's saved us countless hours from dragging-and-dropping the students into groups.
Please let me know if you think it'd be useful at your school, or if you're a Python programmer and would like to help contribute!
I'm going through the process to migrate our users from the legacy Respondus Lockdown Browser integration to their newer LTI integration. As part of this, I want to know which courses have quizzes protected by Lockdown Browser (legacy version), so I can work with those faculty on the changes.
I can see where /Assignments know about Turnitin Settings, but I've not yet found similar API data on Lockdown Browser. Does it exist via API, if so, where? Can the API tell me if a quiz is configured to use Respondus Lockdown Browser?
Thanks, Glen
I really wished that the create APIs would offer the same fields that you get if you do a get. lol
I just discovered that the POST course module does not include the publish state. I've created and ideal but really do not have a lot of faith in the enhancement request process for developer wants/needs as there are many more users who want nice pretty things over backend needs.
We want to create our modules in a published state to help with scalability.
My tidbit is ...
I've been using curl to call the api's when trying things out and the python json.tool module is very useful in that it formats the call results:
curl -v "https://canvas.test.instructure.com/api/v1/users/self/activity_stream \
-H "Authorization: Bearer `cat sis@canvas`" | pyhton -mjson.tool
If the result is json it is nice formatted: not all on one line.
We are up and running a few months now with an API system that allows us to create courses, users and enrollments and then pull down submissions and grades. We're using PHP to read/write to a MySQL database that interacts on our side with our SIS:
SIS <> MySQL <> PHP <> Canvas API
Some of these phps are calling in bulk and some are targeted. We;re starting to get some undetermined fails or errors that we think may be related to API call limits. But there's nothing in results to indicate that, so not sure where all this is documented. We can certainly calibrate but how would I go about determining what the actual rule limits are so I can stay within reason on our side and manage how we hit the Canvas API?
Hi,
I need to enrol users in courses via the API.
The problem is I cannot know the course_id at the time the call is made. This is a problem seeing as the endpoint for enrolling a user is:
Is there any way for me to look up the course_id by some other key such as course_code?
Thanks in advance,
Simon
I'm trying to determine whether a user exists in Canvas via the API by their email.
I'm calling
The single parameter that can be used is described like this:
Returns a list of Users
My API user is an admin.
The problem is that I'm getting unexpected results.
For example, I have 2 users with the same name registered, but with different email addresses:
[
{
"id": 2,
"name": "simon.taylor@icmponline.com",
"sortable_name": "simon.taylor@icmponline.com",
"short_name": "simon.taylor@icmponline.com",
"login_id": "simon.taylor@icmponline.com"
},
"id": 141,
"name": "Simon Taylor",
"sortable_name": "Taylor, Simon",
"short_name": "Simon Taylor",
"login_id": "simon.j.taylor@gmail.com"
}
]
I'd like to determine whether the user with the Gmail address exists:
GET /api/v1/accounts/1/users?access_token=CENSORED5&search_term=simon.j.taylor%40gmail.com HTTP/1.1
But this request returns both of the above users.
Am I doing something wrong?
Thanks,
I'm trying to extract all calendar events from a course (from the beginning of the year to the end of the year). I've tried the 'GET api/v1/calendar_events' call but all I get back is an empty bracket [ ]. Does anyone know how to extract all calendar dates for a single course?
Thanks!
Dave
I need to create a report showing the file spaced used in a course. Last January in the Canvas release notes the item "storage_quota_used_mb" was said to be added to the API (Canvas Production Release Notes (2015-01-31) ). In the documentation for course data I see it listed (Courses - Canvas LMS REST API Documentation ), but that item is not being returned in the data.
I can see "storage_quota_mb", just not "storage_quota_used_mb". I'm calling /api/v1/courses in my curl.
Anyone know why it isn't showing up or where "storage_quota_used_mb" for a course might be found?
thanks,
Matt
Hi all,
Bit of a Canvas API noob here. I've got a call to Canvas to check for presence of a user with <A class="jive-link-external-small" href="https://" rel="nofollow noopener noreferrer">https://</A><SPAN><canvas>/api/v1/accounts/[acc id]/users?access_token=[token no]&search_term=[user email] (</SPAN><A href="https://canvas.instructure.com/doc/api/users.html#method.users.index" title="https://canvas.instructure.com/doc/api/users.html#method.users.index" rel="nofollow noopener noreferrer">Users - Canvas LMS REST API Documentation</A> ), and I'm getting some mixed results. Just in my own testing of url strings I'm finding successful responses with some emails that exist in Canvas but not others where I get []. Searching by ID or name seems to always find the user but email is the only reliable unique identifier we can use. I'm also finding some users on their user profile page have a Default Email value which is different to the login_id value, and using the Default Email value as the search term returns the user while using the login_id value does not. And finally I'm finding some users that are returned when using a search term but not included in the full <SPAN style="font-family: monospace;"><A class="jive-link-external-small" href="https://" rel="nofollow noopener noreferrer">https://</A><SPAN><canvas>/api/v1/accounts/[acc id]/users response. </SPAN></SPAN>
<A class="jive-link-external-small" href="https://" rel="nofollow noopener noreferrer">https://</A><SPAN><canvas>/api/v1/accounts/[acc id]/users?access_token=[token no]&search_term=[user email] (</SPAN><A href="https://canvas.instructure.com/doc/api/users.html#method.users.index" title="https://canvas.instructure.com/doc/api/users.html#method.users.index" rel="nofollow noopener noreferrer">Users - Canvas LMS REST API Documentation</A> ), and I'm getting some mixed results. Just in my own testing of url strings I'm finding successful responses with some emails that exist in Canvas but not others where I get []. Searching by ID or name seems to always find the user but email is the only reliable unique identifier we can use. I'm also finding some users on their user profile page have a Default Email value which is different to the login_id value, and using the Default Email value as the search term returns the user while using the login_id value does not. And finally I'm finding some users that are returned when using a search term but not included in the full <SPAN style="font-family: monospace;"><A class="jive-link-external-small" href="https://" rel="nofollow noopener noreferrer">https://</A><SPAN><canvas>/api/v1/accounts/[acc id]/users response. </SPAN></SPAN>
Is there an admin permission I'm missing, or some secondary email field I'm not seeing which is what the search term actually checks for instead of login_id? Is there anything else regarding a user record which impacts whether their details can be retrieved by API? Appreciate any advice.
I'm an API noob--but I'm hoping to get some help with something I'm experiencing. Its kind of specific for K-12--but I'm hoping someone can help.
I'm trying to make an API call to get a grade for a student in a grading period. We're using the Multiple Grading Periods feature option--and this is the API call I'm making: https://yourinstitution.instructure.com:443/api/v1/courses/{{coursenumber}}/enrollments?user_id={{userid}}&grading_period_id=4
When I make this call--I'm getting a null value for the grade. My grading period ID matches what is returned when I make a call on the grading period. What am I missing?
I have questions about the oAuth refresh tokens mentioned in today's production release. I don't fully understand the implications of this change. What sorts of scenarios would lead to the use of a refresh token? I've read the documentation [OAuth2 - Canvas LMS REST API Documentation ], but I'm still missing something.
There is something else that is new(?) in the oAuth documentation that wasn't mentioned in the notes:
"When the user is asked to grant your application access in step 2 of the web application flow, they will also be given an option to remember their authorization. If they grant access and remember the authorization, Canvas will skip step 2 of the request flow for future requests."
I've never observed that behavior, and I never noticed it in the docs until today, so I'm assuming it is new. What do I have to do as a developer to take advantage of the skipped step? Does the issue of the refresh token depend in any way on the user's decision to 'remember' the authorization? Bottom line, is it safe to assume that my existing workflows will not be disrupted by any of these changes?
Hello All,
I seem to be have in issue with refreshing my canvas token. My process is set to request the authorization code from then redirects to my program to process that code and request a token to be used and stored. Using this initial token I am able to make requests for enrollments, courses, users etc... if that token was deleted or expired then I refresh it and try again.
Below is my request for my initial token with LMS_KEY and LMS_SECRET being values for my actual information.
<?php</P>
$url = "https://felbry.instructure.com/login/oauth2/token";
$oauth = array( 'client_id' => LMS_KEY,
'client_secret' => LMS_SECRET,
'grant_type' => 'authorization_code',
'redirect_uri' => 'https://stars.trainingmasters.com:82/php/FLMS010.php',
'code' => $code);
$header = array('Authorization: Basic ' . base64_encode(LMS_KEY . LMS_SECRET));
$PostFields = buildAuthorizationHeader($oauth);
$options = array( CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLINFO_HEADER_OUT => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $PostFields,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
$headerSent = curl_getinfo($feed, CURLINFO_HEADER_OUT );
curl_close($feed);
$Oauth_Data = json_decode($json,true);
$Token = $Oauth_Data['access_token'];
$RefToken = $Oauth_Data['refresh_token'];
?>
I then use this token to make the request for all completed courses:
$url = "https://felbry.instructure.com/api/v1/courses?state=completed";
$header = array('Authorization: Bearer ' . trim($Token));
$Oauth_Data2 = json_decode($json,true);
echo '
'.print_r($Oauth_Data2,true).'
When I print the result I get a list of all courses as expected.
Then I configure my program to fake a new token so I can trigger my logic to refresh the token. To refresh the token I use the following request $RefToken is the token collected from the initial request:
'grant_type' => 'refresh_token',
'refresh_token' => trim($RefToken));
This Process seems to work since I get a new token but when I attempt to use that new token to make the same courses request as above i receive the following message:
Array
(
[errors] => Array
[0] => Array
[message] => Invalid access token.
)
[error_report_id] => 2259
I have printed all my values out before and after all requests and everything is sending what its supposed to. I have used this process for other Oauth authentication with no issues. Any help with this issue would be great.
Thank you.
I'm just beginning to work on the logic of what I'd like to do, so details are a bit sketchy. I need to add the same new page to the same module in about 75 different courses. The module is named/titled the same in each course, but of course has a different module id in each course. I have the course IDs in a CSV file and plan to loop through those course IDs and create a new page and then add that page to the module. However, I'm not sure how to identify the module ID as I go through each course. Is there a way to specify the module by name/title, or lookup the module ID based on the name/title?
This is a common scenario for us as we frequently have new or updated content that we need to add to many/all of our courses in Canvas. The body of the content is the same for every course and it's always going into the same module which exists in every course. Previously we've had to do this manually, one course at a time, which seems very inefficient.
If anyone has successfully done something similar, I'd love to see the code you used. I'm planning to use Python, but I'm open to other suggestions if someone already has this working.
-Brett
Hi All,
I'm working on a project to scan quizzes for certain combinations of settings that are proving problematic, or that are using either Lockdown Browser or Proctorio.
I'd prefer to not have to load all courses to then load all /courses/quizzes to scan every quiz for it's create/edit date. What I need is a way to use the API to retrieve all quizzes that were created or edited in the last 24 hours. Is there a filter on /quizzes that would do this?
Thanks ,Glen
Anyone have any luck using the Create External Tools API? I am passing the following data to our test enviroment and receive the below error.
{"externaltool":[{"name":"testTool","privacy_level":"public","consumer_key":"consumer_key","shared_secret":"123456","description":"description","url":"http%3a%2f%2fwww.psu.edu"}]}
ERROR:
{"errors":{"name":[{"attribute":"name","type":"blank","message":"blank"}],"consumer_key":[{"attribute":"consumer_key","type":"blank","message":"blank"}],"shared_secret":[{"attribute":"shared_secret","type":"blank","message":"blank"}],"url":[{"attribute":"url","type":"Either the url or domain should be set.","message":"Either the url or domain should be set."}],"domain":[{"attribute":"domain","type":"Either the url or domain should be set.","message":"Either the url or domain should be set."}]}}
Let me set the stage. I am working with the Canvas API
I am making an xhr to a server that sends back 100 results at a time. It returns a 'Link' in the HEADER that looks like this: Link: <</SPAN>https:///api/v1/courses/:id/discussion_topics.json?opaqueA>; rel="current", <</SPAN>https:///api/v1/courses/:id/discussion_topics.json?opaqueB>; rel="next", <</SPAN>https:///api/v1/courses/:id/discussion_topics.json?opaqueC>; rel="first", <</SPAN>https:///api/v1/courses/:id/discussion_topics.json?opaqueD>; rel="last"
Question 1: What is the best way to get the url with the rel="next"? Currently I am doing this (It works but I feel like there is a better way):
function parseHeaderForRel(xhr, rel) {
return xhr.getResponseHeader('Link')
.split(',')
.reduce(function(pv, cv, i) {
if (cv.indexOf('rel="next"') > -1) {
pv.push(cv.substring(cv.lastIndexOf('<') + 1, cv.lastIndexOf('>')));
return pv;
}, []);
Question 2: How do I continue to make calls until the xhr response header no longer contains rel='next'? Also note that the rel="last" is not ALWAYS available, so I don't want to rely on it. I am currently working with something that looks like this.
function getCoursesInAccount(accountId, data, url) {
data = data || [];
url = url || '/api/v1/accounts/' + accountId + '/courses?per_page=100';
return $.get(url).done(function(res, textStatus, jqXHR){
var url = parseHeaderForRel(jqXHR, 'next')[0];
if(url){
data.push(res);
getCoursesInAccount(accountId, data, url)
} else {
console.log(data);
return data;
})
The console.log will always log the correct data, but I can't get it out of the function and I want this to be a service I can call upon in other functions. I have played with just returning the entire $.get() and using 'then' but I don't know how many 'then's I will need.
Any direction is greatly appreciated!
@kenneth_larsen - I heard you know things.
Just posted about a new LTI tool that we developed at Eastern Washington University that displays visualizations of Canvas discussions.
Visualize Discussions - Threadz
Alright everyone, I'm trying to decide on a topic for 2016 InstructureCon. Chime in and vote now at What should Kenneth Larsen present on at InstructureCon 2016?
I am attempting to add an assignment that uses an External Tool
The external tool has been created and tested to ensure it is functional. I can create assignment and module items in the GUI, but am having difficulty creating an assignment with the API that uses an External Tool.
Below is the CURL command that I am using
curl 'https://ecpi.instructure.com/api/v1/courses/896/assignments'
-d 'assignment[name]=ECPI Post Test'
-d 'assignment[submission_types]=external_tool'
-d 'assignment[external_tool_tag_attributes]=url:https://test.ecpi.net/quiz/connect_post.php,new_tab:true'
-d 'assignment[points_possible]=100'
-d 'assignment[grading_type]=points'
-d 'assignment[assignment_group_id]=4083'
-H 'Authorization: Bearer 4534~ETXXXXXXXX'
(yes, the token has been changed in the code above)
The output I get is an error message that give no help
{"errors":[{"message":"An error occurred.","error_code":"internal_server_error"}],"error_report_id":46141}
Does anyone have any idea as to why the command fails with an error?
The API documentation says that a course can be in different states. Does anyone know what the definition is for these different states? What is the difference between "claimed" and "available"? Or to be more precise, what does the "claimed" state mean, is it simply "unpublished"?
Canvas LMS REST API Documentation
Thanks for any clarity you can provide.
We want to add rubrics to each of out discussions. I looked through the API documentation and cannot find an endpoint for Rubrics, but can find the RubricRating object and RubricCriteria objects references in the Assignment endpoint documentation Assignments - Canvas LMS REST API Documentation
Does anyone know how to link preexisting rubric to a graded discussion?
Hi Kenneth,
Thanks for your reply. Yes. The original filedata I was testing on POST was string 'name=words.txt&size=475954&content_type=text/plain&parent_folder_path=Eval Reports/Fall2015'.
I simplified the note on the code paste above. I did just tried the suggestion you gave, changed the folder name without space, but still didn't got the file name passed in.
UI for weekly progression idea that rest in the Schedule tab of the **K-12 UI** of Canvas it's incomplete and I really would not take it and push it into instance but I am going to post it here because in the past people like @James && @robotcars || @Steve_25 have had terrific input in the past... maybe w/their eyes and…
A case for this argument: I live in thee K-12 realm which means we have way too many assignments... which means that at times a simple last 10 assignments of a course question(last 10 date wise) will take us 300 assignments to answer Solution for this example in particular: I would love to make this modified version of an…
Hey Community: I want to ask first if Canvas LMS as a Identity provider is only supported with SAML? What other protocols are supported? My use case is that I have a React App hosted on cloud provider (AWS) and SpringBoot as a backend (Service provider). I want to integrate Canvas SSO as a Identity provider (IdP). I…
Hi , I’m working on validating the API test cases for CANVAS Api and need suitable test data to verify the 200 OK status code responses. I am using free for teachers version account. PFA Ecel sheet about the end points I am checking for.
I am attempting to programmatically access the LTI usage data presented in the Canvas Apps Dashboard (total launches, unique users, subaccounts, courses over time). Could anyone advise on the best method to replicate this information by using the Canvas Rest API calls or Canvas Data 2?