Forum Discussion

fuenteso's avatar
fuenteso
Leader
7 years ago

Update a user avatar using the API

Hi everyone,

 

We're adding new avatars to our community and we want to delete the old ones, which will leave us with a lot of broken avatars. 

 

I've been looking here for a solution and I know I can use JavaScript to catch those broken images and replace them at runtime. The problem is this doesn't resolve the problem (users having a broken avatar), in fact, it hides it and there's no way for users to know if they have a valid avatar or not.

 

We're considering using the API to modify each user profile using a non-custom avatar to replace it with a default avatar, but I can't find anything on the documentation. API v1 doesn't have a call for that, in fact, the documentation says that we have to use API v2 for that. But apparently, endpoints are not allowed to make HTTP calls to any .lithium.com domains.

 

Is building a mini-app on a different server, going through the authorization process and make the call the only way to update another user's avatar? Am I missing something?

 

Thanks!

  • We had an issue where users' avatars, especially if they had used external ones at some point, where missing and it looked horrendous.

    I added a one-click button for admins and mods on the profile page that will pick randomly from our set of uploaded avatars.

     

    Long story short, API 1 works just fine for this. The frontend button, on click, pulls from an array of options, then sends the randomly selected one to an endpoint.

    Our endpoint simply does the below. As you can tell from the end it's just set to pick from a certain folder in our assets/avatars section:

    <#assign result = restadmin("/users/id/${user_id}/profiles/name/url_icon/set?value=avatar:candy/Spotify_New/${user_avatar}")/>
  • We had an issue where users' avatars, especially if they had used external ones at some point, where missing and it looked horrendous.

    I added a one-click button for admins and mods on the profile page that will pick randomly from our set of uploaded avatars.

     

    Long story short, API 1 works just fine for this. The frontend button, on click, pulls from an array of options, then sends the randomly selected one to an endpoint.

    Our endpoint simply does the below. As you can tell from the end it's just set to pick from a certain folder in our assets/avatars section:

    <#assign result = restadmin("/users/id/${user_id}/profiles/name/url_icon/set?value=avatar:candy/Spotify_New/${user_avatar}")/>
    • fuenteso's avatar
      fuenteso
      Leader

      Awesome! That's exactly what I was looking for. I just tested it and it works.

       

      It's a shame that the documentation doesn't have this option on the 'avatar' part.

       

      Thanks, again!

  • fuenteso - You can delete the old avatar and upload a new one with the same name.  With this approach, there wouldn't be any broken avatar. I found this from https://community.lithium.com/t5/Developer-Discussion/Changing-custom-avatar/m-p/430986/highlight/true#M13457

     

    Also, this thread might be useful https://community.lithium.com/t5/Developer-Discussion/How-to-replace-default-set-of-avatars/m-p/279966/highlight/true#M11200

     

    Regarding the API V1, yes there is no API V1 for upload the new avatar. You will need to use API V2 from a different server.  I have tried to make API V2 from an endpoint however, lithium doesn't allow this. 

    • fuenteso's avatar
      fuenteso
      Leader

      Thanks for the suggestion, but unfortunately we're not just updating the avatars, we want to introduce a completely new theme for avatars so we don't have a 1:1 correspondence between the old and new ones.