Updating avatar using Canvas API

Jorge-Dev
Community Member

Hi eveveryone, 

I'm a developer and I'm automating the update of user avatars using the following endpoint (using Python 3):

https://canvas.instructure.com/doc/api/users.html#method.users.update
PUT /api/v1/users/:id

We're having issues with some users not getting their avatar updated while others do. 

We are successfully sending the http request:

  • as a parameter, i pass the token for the uploaded file that I want to set as the avatar
  • this file is already successfully uploaded to the user's "profile pictures" directory.
  • To remove any other variables, we uploaded the same image for each of the users
  • we get a response, with status code of 200

However, we're not getting consistent results. 

In the http request response for each user, we see two scenarios:

  1. Success - The first is when the avatar update is successful
    • the response text includes user details
    • in the details, i can confirm that the avatar has been updated to the corresponding photo matching the token sent
    • in there, I can also verify that the avatar state is locked, which is what we want
  2. Not Updated - The second scenario is where the avatar is not updated
    • the status code is 200 for this also, no http error
    • the response text includes user details, but with fewer detail fields when compared to the details we get from scenario 1 above
    • in this scenario's details, we can see the avatar url is pointing to this particular file:   our_domain/images/messages/avatar-50.png
    • we have tried to see if there is a difference in the users that fail, but have not found anything that diffirentiates them
    • in addition, there have been times when some users who had their avatar updated successfully before (scenario 1 above), now fall under this 2nd scenario

We have only done this in our TEST environment. 

Any ideas on what is causing this?

Thanks in advance for your help!

Labels (5)
0 Likes