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

Question about Rest API call, List Users in Accounts

I am new to Canvas development and I was hoping for some help with Rest API call. I was trying to get a list of the existing users from Canvas and the close API call I can find is the following. Any advice, suggestions will be most welcomed.

GET /api/v1/accounts/:account_id/users

I try to understand what is account ID? How can I find the account id?

In addition, when I make a Rest call, https://canvas.instructure.com/api/v1/accounts/self/users and specify the token in the header, got the error below,

{
"status": "unauthorized",
"errors": [
{
"message": "user not authorized to perform that action"
}
]
}

4 Replies
James
Navigator

 @wendy_lin ‌,

Make sure that you're using your instance rather than canvas.instructure.com. You're not authorized on canvas.instructure.com, which is why it didn't work.

You can also test out API calls that use GET by logging into Canvas and then changing the URL to match the API call. It will most likely include a while(1){}; at the beginning, but everything after that will be the output you would get.

You can get the account ID by going to the Admin button in Canvas and then mousing over the name of your site. It will be in the URL at the end. You can use self though and it will figure it out based on the Canvas instance you're using.

wendy_lin
Community Member

Thanks James for the reply. It is very helpful. I made changes to the URL and it starts returning a list of the users. However, it doesn't return all the users in our instance. There are at least 100 accounts in our instance, but the service call returns only 9 users. I try to understand why it doesn't return all the users. Here is the URL,

https://XXX.instructure.com/api/v1/accounts/1/users 

You're ran into the pagination issue. The quick fix for many items is to add a query parameter of per_page=100 to the call. That will work for small data sets, but will eventually break once you surpass 100. There is an undisclosed upper limit that might vary from call to call, but 100 has seemed pretty stable and usable and if it is too big, it will shrink it for you. All that to say that when you get more data, you won't be able to just bump the 100 up to 200 or 500 or 1000 and have it work.

The long-term fix is to deal with pagination as explained in the Basics section of the API documentation. Here's the direct link: Pagination - Canvas LMS REST API Documentation 

chofer
Community Coach
Community Coach

Hi  @wendy_lin ‌...

I thought that I would check in with you because there hasn't been any new activity in this discussion thread since  @James ‌' reply on February 14th.  I am hopeful that James has been able to help answer the question(s) you had.  So, I will go ahead and marked your question as "Assumed Answered", but that won't prevent you or others from posting additional replies below.  Also, if you feel that one of the replies from James is "Correct", please go ahead and mark it as such.  Looking forward to hearing from you soon, Wendy.