Disabling users by setting login workflow_state to suspended?

szalontay_zolta
Community Member

Dear community, I am new to Canvas and its API. 

As many others here, I would like to be able to disable and enable my users temporarily. AFAIK there is no direct API call for this so my idea is the following:

- Search user by its SIS ID (which is identical to the email address in my case)

- Get the list of logins for the user (I only give one login for my users)

- Call the edit login API (https://canvas.instructure.com/doc/api/logins.html#method.pseudonyms.update) and set "workflow_state":  "suspended". If I understand well, this would disable user login.

Would this work? Does this method have any disadvantages over the others? 

P.S.: It would look stg like this using the Canvasapi Python package:

=============================================
from canvasapi import Canvas

API_URL = "https://<canvas-url>.instructure.com"
API_KEY = "<insert-api-key-here>"

canvas = Canvas(API_URLAPI_KEY)
sis_id = "a@b.com"
user = canvas.get_user(sis_id"sis_user_id")
logins = user.get_user_logins()
for login in logins:
    login.edit(login={"workflow_state""suspended"})

=============================================

Thx,

Zoltán

Labels (1)
0 Likes
Users who also had this question