Custom avatar with Jira API

Martin Stiborsky March 1, 2012

Hello,

I'm trying to create custom avatar with Jira API (Jira 5). I need somehow create new "Avatar" object…but I didn't find such method in any @PublicApi classes…only one such I'd need is in AvatarImpl class, which belongs to jira-core artifact, which as I can see, is not recommended to use…

Is there any other way? For example with "public" API classes & methods? Or the impl class is good enough?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Dieter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 1, 2012
Hi Martin, the AvatarManager interface is in the public Api, so you do not need to worry if you create your Avatars using that interface. Please check http://docs.atlassian.com/software/jira/docs/api/latest/com/atlassian/jira/avatar/AvatarManager.html You can get the interface through the ComponentAccessor
Dieter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 1, 2012
ComponentAccessor.getAvatarManager() gives you the interface you need
Martin Stiborsky March 1, 2012

Hi Dieter,

thanks for reply!

Yup, AvatarManager is ok for me, but I'm confused about how to get new "Avatar" object that I can pass as new Avatar to AvatarManager. So, how to create new "Avatar" type object? AvatarImpl and there method createCustomAvatar?

Or I'm totally wrong? :)

Martin Stiborsky March 1, 2012

ok, I see now :) Thanks a lot!

Dieter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 1, 2012
Hi Martin, the create methods require an existing Avatar as template. So you.could first use http://docs.atlassian.com/jira/4.4/com/atlassian/jira/avatar/AvatarManager.html#getAnonymousAvatarId() to get the avatar id of the unknown user and then use this id with method http://docs.atlassian.com/jira/4.4/com/atlassian/jira/avatar/AvatarManager.html#getById(java.lang.Long) to get an Avatar template that you can finally pass in the create method. Not straightforward but that should give a new Avatar
Martin Stiborsky March 1, 2012

But…still problematic…I have same problem as here: https://answers.atlassian.com/questions/10092/null-pointer-exception-when-creating-an-avatar :( Any idea please? I can't find the null reference…

Martin Stiborsky March 2, 2012

Problem solved :)

Martin Stiborsky March 2, 2012

Ok good, I'm able to upload new avatar with Jira api…I think there is one bug…when I upload new image as avatar, which owner is "admin", then the thumbnail in the "change avatar picture" dialog in jira user profile is missing, there is just the usual "missing picture" image. With normal user it is ok, no problen.

One more question, I can't find method for actual change of avatar for specifi user…Is there somethink like this? Have to be, because it is possible through REST API…I really how to download Jira source codes at monday, at work :)

EDIT: ooops, I lied a little bit…there is not such method for just "changing" of avatar for user…

I have messed up all these things now, need some rest :)

Martin Stiborsky March 2, 2012

I'm talking here with myself, but nevermind, next problem has been solved.

I'm lame and blind :D Sure in REST API is a method to actually change the user's avatar.

PUT /user/avatar

username as parameter

JSON payload (example): {"id":"10113","isSystemAvatar":true,"isSelected":false}

Woohoo, it works :D I'm really happy :D Now I have probably all major problems solved…

Btw, many thanks to Chrome "Inspect tool", I don't know how it is exactly called, it is like Firebug in Firefox…I was able to research REST calls in Jira Avatar settings and find the one I need this way. (I know the PUT /user/avatar is in documentation, but, you know how it goes when one is lame as me :D)

Also the REST Api broswer is Jira is great tool…

TAGS
AUG Leaders

Atlassian Community Events