Skip to content

How to Test the Canvas API

Sean Hammond edited this page Jan 15, 2020 · 1 revision

See also:

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.

  1. 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.

  2. 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'
    
  3. 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