cancel
Showing results for 
Search instead for 
Did you mean: 
ahaight
Community Member

Making a Basic API Call with an Access Token

Jump to solution

Hi!

I'm having trouble making a very basic GET request with a user-generated access token. I'm using the python module "requests" to make my requests. My request looks like:  data=requests.get('https://clemson.instructure.com/api/v1/accounts?access_token= with my access token following.

When I print the results, however, using print(data.json()) all that prints is "[]".

Please let me know what I am doing wrong. 

Tags (3)
1 Solution

Accepted Solutions
pklove
Community Champion

When using API gets with a user token, if you want to rule out things like problems with your code or the user access token, you can simply log in as the user and put the API URL into your browser.  What you get back should be what you get back from your code.

View solution in original post

3 Replies
nardell
Community Participant

Alex :: I don't think the authentication is failing (otherwise you would get a 401 Error Code). Looking at the Canvas API documentation, the endpoint for accounts will return:

A paginated list of accounts that the current user can view or manage. Typically, students and even teachers will get an empty list in response, only account admins can view the accounts that they are in.

One other note, I think it is better to put the Access Token in the header. That Access Token can be used by any HTTP call from any system, to do anything you can do in Canvas. 

Mike

pklove
Community Champion

When using API gets with a user token, if you want to rule out things like problems with your code or the user access token, you can simply log in as the user and put the API URL into your browser.  What you get back should be what you get back from your code.

View solution in original post

pklove
Community Champion

A simple endpoint that you could try without having to worry about being an admin or having any particular permissions is: .../api/v1/users/self

Or if you have active course enrolments: .../api/v1/courses