[ARCHIVED] Return Users with Last_Login - Pagination

Jump to solution
cmarsh1
Community Novice

Hello! I need to export a list of all users that includes their last_login attribute, and hopefully find a way to reset the password or any user that hasn't logged in for a set period of time - say 180 days.

I can pull the first 10 users with the call below but can't seem to get it to the next page of results. Every variation I have tried so far gives me the error "{"status: unauthenticated","errors":[{"message":"user authorization required"}]}" - even though I'm passing my token and authenticate successfully for the first page or results. Has anyone run into this, or can you tell me what I'm doing wrong? I'm new to Canvas and the API so don't have much experience yet.

My command:

curl https://myuniversity.instructure.com/api/v1/accounts/1/users?include[]=last_login -G -H 'Authorization: Bearer This-Is-My-Super-Secret-Token'

Command I'm trying to get the next page of results that fails:

curl https://myuniversity.instructure.com/api/v1/accounts/1/users?include[]=last_login&page=2&per_page=10 \ -G -H 'Authorization: Bearer This-Is-My-Super-Secret-Token'

Labels (2)
1 Solution
bbennett2
Community Champion

I don't see anything wrong with your command. You can specify results with the `per_page` param on your initial request that will carry forward with the `<Link>` header param you get back (get 100 at a time, for example). 

Are you using an API client like Postman? Or using the terminal directly? Is there any way for you to inspect the response headers?

Also, if you're comfortable using Python, there is a fantastic open library for the Canvas API that makes work like this much easier.

View solution in original post