Updating User Notification Settings via API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I'm generating a group of users via a SIS upload then trying to go through each profile and switch off all notifications for each user. Currently I have a script that looks up the user's communication channel id and then tries to switch just the first notification preference to "never".
But on the second step, I'm hitting a 500 error and I'm not sure what I'm getting wrong. I'm sure it's something simple. Here's the segment of my code I'm having trouble with:
foreach($parent in $Parents){
$apiURL1 = $domain+"/api/v1/users/sis_user_id:"+$parent.user_id+"/communication_channels/"
$data1 = (Invoke-WebRequest -Headers $headers -Method GET -ContentType 'application/json' -Uri $apiURL1)
$userChannel = $data1.Content | ConvertFrom-Json
$channelAPI = $domain+"/api/v1/users/self/communication_channels/"+$userChannel.id+"/notification_preferences?as_user_id=sis_user_id:"+$parent.user_id
$BodyData = @{"notification_preferences[course_content][frequency]" = "never"; "notification_preferences[due_date][frequency]" = "never"}
$json = $BodyData | ConvertTo-Json
$data2 = (Invoke-WebRequest -Headers $headers -Method PUT -ContentType 'application/json' -Uri $channelAPI -Body $json)
}
Any ideas?
Thanks,
Rob