-
Notifications
You must be signed in to change notification settings - Fork 14
How to Test the Canvas API
See also:
- The docs for Canvas's REST API: https://canvas.instructure.com/doc/api/all_resources.html
- The docs for Canvas's GraphQL API: https://canvas.instructure.com/doc/api/file.graphql.html
- Canvas's GraphQL explorer page: https://hypothesis.instructure.com/graphiql
If you login to Canvas you can generate an API access token for your account that you can use to call different API endpoints with different parameters using HTTP tools such as curl, HTTPie, etc, and see the results. We'll use HTTPie in this tutorial.
-
Log in to Canvas and add an access token to your account (Account -> Settings, scroll down to Approved Integrations, + New Access Token). You probably want to create an access token with no expiry time. Copy the token, because you'll need to paste it for the next steps.
-
Use HTTPie to call the Canvas REST API, pasting the access token that you generated in step 1 above into an
Authorization:'Bearer <ACCESS_TOKEN>'
header. Remember to prefix the access token with"Bearer "
. For example:$ http 'https://hypothesis.instructure.com/api/v1/accounts/1/users' Authorization:'Bearer 9382~1HA***z7X'
-
You can also use HTTPie with the same
Authorization:'Bearer <ACCESS_TOKEN>'
header to call the Canvas GRAPHQL API, but the commands are a little more difficult to type. Here's an example:$ http --form POST 'https://hypothesis.instructure.com/api/graphql' Authorization:'Bearer 9382~1HA***z7X' query='query courseInfo($courseId: ID!) { course(id: $courseId) { id _id name } }' variables[courseId]=1