cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Community Team
Community Team

All things API

Have a question about the Canvas APIs? Have a cool API integration you'd be willing to share? If so, please post here.

Labels (1)
Tags (1)
271 Replies
Highlighted
Community Member

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!

Highlighted

Katerina.... 

I think the most intuitive thing is to play with URLs right in the browser, for instance, try going to the URL:

https://yourinstance.instructure.com/api/v1/courses

(Make sure you are logged into Canvas in another browser tab first)

You will get a list of courses you are enrolled in.  It will look a bit cryptic, the encoding is called JSON, but it is still very human readable.

You can see how to build these URL requests by looking at Canvas's API reference:

Canvas LMS REST API Documentation

Pick a programming language you like, and most of them have an easy way of reading JSON. 

Easiest way to get started is to think about writing custom reports.  A simple command line report that creates a .csv file is not many lines of code.  I recommend sticking to "GET" requests (read-only)  till you get comfortable.  If you make requests other than "GET" requests make sure you test on the beta or test sites first.

Best to pick a programming language first (many non-programmers like powershell).  If someone at your institution writes code, talk to them and consider using whatever they use.  Then read up on how to make REST API calls and handle JSON in that language....  most likely you can find some code you can modify.

Josh

Highlighted

Josh, thank you so much for taking the time to write your reply. I will definitely look into it! Picking a programming language was one of my questions. Yes, we do have code-writers but they provide support to 21 campuses in our organization and I only represent one campus (which also happens to be the biggest one) so we are looking at writing some custom APIs for our campus. Thank you again and have a great day!

Highlighted

A scripting style language is simplest...  PowerShell or Python might be good choices.... 

Highlighted
Community Member

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.

Highlighted

Awesome, thanks again! I will dig into this when I get any downtime from my daily Canvas admin duties Smiley Happy On a side note, is anyone familiar with this converter? JSON to CSV

It looks like a really easy way to produce a csv just by pasting JSON in the box (especially for beginners) and get a readable report literally in matter of seconds. Is it too good to be true? Smiley Happy

Try this one:

http://jsonformatter.curiousconcept.com/

Cut & Paste the JSON data returned by Canvas.  Then delete by hand the following from the beginning of that data:

while(1);

The while(1); is not part of JSON...  it is added as a security measure (don't worry about the why... just delete it to look at the data).

Josh

Please note, you cannot just pass in the URL and expect it work since the website can't access your Canvas account.  While you could pass the token with the URL, DON'T do this!  It is a big security risk to trust your secret token with a remote site.

Highlighted
Community Member

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

Highlighted

Hello Jacques,

I am indeed the one who started this thread but regret to inform you that I don't personally have the technical know-how to adequately respond to your questions.  Hopefully some of the others who have been active in this group, like kenneth.larsen@usu.edu​, travis.thurston@usu.edu​, or karl@instructure.com​, will know better than I.

Thanks,

SD