A demo of the CanvasCBL API, written in Node.JS.
Just looking for the API docs? https://go.canvascbl.com/docs.
- Clone repo
git clone https://github.com/canvascbl/api-demo-node.git
- Enter the directory
cd api-demo-node
- Set up your env vars-- you can do this with your favorite text editor
- Create a file called
.env
- Fill it with key-value pairs, one per line.
CLIENT_ID=yourcanvascblclientid
CLIENT_SECRET=yourcanvascblclientsecret
REDIRECT_URI="http://localhost:8002/response"
- if your server is somwhere else or on a different port, change this!- Make sure this is authorized in your CanvasCBL Developer Key!
- Create a file called
- Make sure Node.JS (the version in the
.nvmrc
) is installed. On a Mac, runbrew install nvm
, thennvm install && nvm use
. - Install deps--
yarn install
(preferred) ornpm i
- Run the server--
yarn start
(preferred) ornpm run start
Now we can start using the server-- check that out here.
- First, you'll need to be redirected to CanvasCBL for authentication.
To do this, visit
http://localhost:8002/authorize
for this. Specify scopes with thescopes[]
query param. You'll only need grades, so your final authorize call should look like this:http://localhost:8002/authorize?scopes[]=grades
. If you just want to preview the URL you'll be sent to, append&redirect=false
. - Once you've signed into CanvasCBL and authorized the request, you'll be redirected to
http://localhost:8002/response
. This is your Redirect URI, and you should see the tokens from the new grant! - Get some grades: visit
http://localhost:8002/grades
to see them. - When you're done, you can visit
http://localhost:8002/clear
to clear all cookies and void the grant.
That's it!
You can also use /tokens
to see all the stored tokens (also in your cookies).
You'll see that all API URLs in the code look like this: ${env.canvascblApiUri}/path
. This is to
support the CANVASCBL_API_URI
environment variable. In your code, you shouldn't do this-- just
use https://api.canvascbl.com/path
. It'll never change.
That functionality is there for internal usage.
The following code snippet shows a completely filled out .env
file.
# CanvasCBL API Client ID
CLIENT_ID=yourcanvascblclientid
# CanvasCBL API Client Secret
CLIENT_SECRET=yourcanvascblclientsecret
# Redirect URI. Must be on your list of approved URIs and
# point to this server with the path of /response.
REDIRECT_URI="http://localhost:8002/response"
# --- Advanced, Optional Env Vars Below ---
# [OPTIONAL] The port for the server to run on
PORT=8002
# [OPTIONAL] The URI for the CanvasCBL API
CANVASCBL_API_URI="https://api.canvascbl.com"
We love PRs! Please make sure that your code is formatted using yarn format
or npm run format
before submitting.
We also do not accept PRs that add an NPM lockfile-- please use Yarn for PRs.