How do I list users then terminate a user's sessions? #593
-
Hello, I am trying to figure out how to list users with this endpoint using the python canvasapi: My ultimate goal is to terminate sessions for a user: I know how to get a user by ID, but I don't know the ID of the user so believe I need to search for them first by using the endpoint mentioned above. Is it possible to get a user directly by passing the user's email? All of the examples I see use user ID but the ID isn't obtained from anywhere, it is just hard coded. Thanks for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Yes, you can use that first endpoint to find the user. The
So, if you know your user's email address, you can do something like this: # Set up your canvas instance, etc
account = canvas.get_account(1)
user = account.get_users(search_term="myemail@example.com")
# get_users returns a paginated list, so you can check by iterating
# If more than one user is returned, be sure to check that it's the person you want
for u in user:
print(u.name)
# Do stuff |
Beta Was this translation helpful? Give feedback.
-
Great thanks! I am able to get a canvasapi.user.User object now by searching for email. Now I can't find how to terminate the user's sessions. There doesn't appear to be anything in the User object. I reviewed the code but maybe I missed it. How can I terminate all sessions for a user? |
Beta Was this translation helpful? Give feedback.
Yes, you can use that first endpoint to find the user. The
search_term
kwarg can be used and it should be as specific as possible, like a full email address. From the Canvas docs (my emphasis added):So, if you know your user's email address, you can do something like this: