Community Member

Setting User Avatars Powershell

I am a systems admin at a community college that uses a local active directory domain. As such we use powershell to automate our systems. I have got a working solution for sis imports, but those do not include user avatars. Thus I have written a script to do so in powershell, however I cannot seem to get the uri correct. This is the code I am using (with confidential parts substituted with <*>) : 

$Token = '<token>'

$headers = @{"Authorization"="Bearer "+$Token}
$date = get-date -format "yyyyMMdd"
$csv = import-csv "<server-path>\$date\1usersAcct.csv"

foreach ($_ in $csv)
$id = $_."user_id"

$login = $_."login_id"
$uri = "https://<canvas test environment>/api/v1/users/sis_user_id:$id/"
$filename = "<path to photo>.jpg"
if (Test-Path $filename)
Invoke-RestMethod -uri $uri -Headers $headers -Method Put -InFile $filename -ContentType "image/jpg"
Write-Host $login

Everything here is working except I get a unprocessable entity error whenever I add anything to the end of the URI like /avatars, /profile, /profile pictures. /files/28290, /folders/28290, and I have tried many others. 28290 is the profile pictures folder id. Yet, when I just end it at the uri shown above it lists all of the items in a users container, such as content, status code, status description and the like. All this is to say I believe I just need the correct uri, and cannot find the uri I am looking for anywhere on the canvas forums, or on other forums like stack overflow. Any help would be  appreciated.


Labels (4)
0 Replies