I have an issue I can't figure out. It is a syntax problem that can't solve. Let's say I have this function:
function putStudentCourse ($userName, $courseId)
{
$url = "http://myurl/learn/api/public/v1/courses/courseId:" + $courseId + "/users/userName:" + $userName
$contentType = "application/json"
$basicAuth = post_token
$headers = @{
Authorization = $basicAuth
}
$body = @{
grant_type = 'client_credentials'
}
$data = @{
courseId = $courseId
availability = @{
available = 'Yes'
}
courseRoleId = 'Student'
}
$json = $data | ConvertTo-Json
$putStudent = Invoke-RestMethod -Method Put -Uri $url -ContentType $contentType -Headers $headers -Body $json
return $json
}
And then my main method:
#MAIN
$userName = "user02";
$courseId = "CourseTest101"
$output = putStudentCourse($userName, $courseId)
Write-Output $output
Right now it is just returning the first vale ($userName) but the output shows like this:
{
"availability": {
"available": "Yes"
},
"courseRoleId": "Student",
"courseId": null
}
Somehow $courseId is never filled and I am not sure why. What am I doing wrong? Any help will be appreciated it.