I am trying to change the course code via the canvas api. I can get it to work in bash with the example the give
curl -X PUT -H 'Authorization: Bearer w3KhVblthisisnottoken5LmhlnUorFM8NJMh0' \
https://school.test.instructure.com/api/v1/courses/9066 \
-d 'course[course_code]=holla!' \
-v
I try to reproduce this in powershell. The call goes through, but it does not do anything!
function Update-CanvasCourseName(
[Parameter(Mandatory = $true)][string] $CourseId,
[Parameter(Mandatory = $true)][object] $header,
[Parameter(Mandatory = $true)][string] $url,
[Parameter(Mandatory = $true)][string] $name
){
$uri = "$url$CourseId"
$body = @{"course[course_code]" = $name}
Invoke-WebRequest -Headers $header -Body $body -Method put -Uri $uri
}
$header = @{"Authorization"="Bearer $(C:\PowerShells\decryptText.ps1 -FilePath C:\Credentials\canvasapi.txt)"}
$course = 9066
$url = "https://holyfamily.test.instructure.com/api/v1/courses/"
Update-CanvasCourseName -CourseId $course -header $header -url $url -name "please work"
has anyone have this issue before? IS there something in my code that I am doing wrong? I cannot reproduce what I can do in curl.
Solved!
The problem was that I was using the wrong content type. For Canvas LMS, multipart/form-data must be selected when doing a PUT call.
The problem was that I was using the wrong content type. For Canvas LMS, multipart/form-data must be selected when doing a PUT call.