[ARCHIVED] Need help with a PUT call to set notification preference in Canvas API that is failing (CURL & API)

Jump to solution
it3
Community Participant

I am trying to set notification preferences in Canvas (instructure) LMS using CURL. I can get all the preferences so the User and communication channel is fine. I can put some other data but not a new notification preference. Eventually I would like to put a value for the category, but for now just trying to set one notification preference

**This command works fine - get the value of the notification preference**
curl.exe https://<myschool>.instructure.com/api/v1/users/33/communication_channels/38/notification_preferences/new_announcement -H "Authorization: Bearer <token>"

**RETURNS**
{"notification_preferences":[{"frequency":"never","notification":"new_announcement","category":"announcement"}]}

**This command works fine (example of a put via curl)**
curl.exe https://myschool.instructure.com/api/v1/courses/473/front_page -d wiki_page[body]=”something new” -X PUT -H "Authorization: Bearer token"

**This command fails - trying to put a new value for the notification preference**
curl.exe --verbose https://<myschool>.instructure.com/api/v1/users/33/communication_channels/38/notification_preferences/new_announcement -d notification_preferences[frequency]=”immediately” -X PUT -H "Authorization: Bearer <token>"

**ERROR in HTML:**
<p>
There was a problem with your last request.
You may have tried to perform an action after a long period of inactivity.
If that's the case, try going back, reloading the page you were working on, and resubmitting.
If not, please let us know what you were doing when the error happened.
</p>

**ERROR inside the CURL RESPONSE:**
HTTP/1.1 422 Unprocessable Entity

Any help is appreciated

Labels (2)
0 Likes
1 Solution
robotcars
Community Champion

It doesn't explicitly state it, but in the GET requests there is a :user_id, and in the PUT requests it's just self and only self will work, even for yourself as an admin.

 

curl --verbose  "https://*.instructure.com/api/v1/users/self/communication_channels/#/notification_preferences/new_announcement?notification_preferences[frequency]=immediately" -X "PUT" -H "Authorization: Bearer $token"


curl --verbose  "https://*.instructure.com/api/v1/users/self/communication_channels/#/notification_preferences/new_announcement" -d "notification_preferences[frequency]=immediately" -X "PUT" -H "Authorization: Bearer $token"

 

View solution in original post