Creating user via API

ross_gailer
Community Member

I have had a powershell script working for creating users in Canvas, but now for some reason it is broken and I can not see why. I have added lots of debugging to check that I am actually getting the json data built correctly and it does all appear to be there. I am getting 400 errors.

Any help with what has gone wrong with this would be appreciated

#Now we create the Canvas user......
#Set the headers
$headers = @{
Authorization= "Bearer <token>"
}
$url = "https://<our instance>.instructure.com/api/v1/accounts/1/users"
#Create the body with the variable data in it
$jsontxt = @"
{
"user": {
"name": "$name",
"short_name": "$givenName"
},
"pseudonym": {
"unique_id": "$mail",
"sis_user_id": "$sam",
"authentication_provider_id": "2"
},
"communication_channel": {
"type": "email",
"address": "$mail"
}
}
"@
$method = "POST"
#Lets see if we can build a call
#check the url
write-host $url
write-host $headers
write-host $jsontxt
try {
Invoke-RestMethod -Uri $url -Method POST -Header $headers -ContentType "application/json" -Body $jsontxt
} catch {
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
Write-Host $_.Exception
}

Labels (1)
0 Likes