Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,658
Community Members
 
Community Events
176
Community Groups

Insight Rest API: Object Avatar Upload

Edited

I want to upload an image as an Avatar to an Insight object from my code, ideally using a Rest call.

https://documentation.riada.io/display/ICV50/Insight+with+JIRA+REST-API

lists only a get method to retrieve the Avatar but not to set it.

Now, when I upload it manually I can sniff on the network a call to:

<jira-base-url>/jira/plugins/servlet/com.riadalabs.jira.plugins.insight/avatarupload

I also add the file and as usual the

headers = {'X-Atlassian-Token': 'no-check'}

 I end up with the error message:

{
    "error": {
        "system": "Upload error, are you uploading a valid image?"
    }
}

in the response header. I get the same when using eg. Postman to call the endpoint. When I replay the call from the network sniffer it does work with the same file.

Does somebody have a similar issue, and were you able to overcome it? Any hints welcome.

Many thanks in advance.

Christian.

1 answer

1 accepted

1 vote
Answer accepted
  1. You have to define a UUID for the avatar and send that along the request. So you send multipart/form-data with parameters:
    1. file - your file
    2. avatarUUID - your UUID
  2. Next, you need to update the Insight object via PUT /rest/insight/1.0/object/<objectId>, json body is like this (you have to send at least one attribute value or it will return 400):
{
"attributes": [
{
"objectTypeAttributeId": <objectTypeAttributeIdOfLabelAttribute>,
"objectAttributeValues": [{"value": "Test Avatar"}]
}
],
"objectTypeId": <objectTypeId>,
"avatarUUID": "<yourUUID>",
"hasAvatar": true
}

Hi Alexander,

this works for me, thanks a lot.

Here is what I sent along with for the first POST request:

import uuid
...

url = "{}".format(
Config.urls()["base_url"]
+ "jira/plugins/servlet/com.riadalabs.jira.plugins.insight/avatarupload"
)
uid = str(uuid.uuid4())
logging.info("Generated UUID %s: ", uid)
data = {"avatarUUID": uid,
"name": "rlabs-insight-object-avatar"}

r_post = send_request(url, None, "post", data=data, filename=filename)

 it does not have to be uuid4, any of the options will do.

Best regards,

Christian.

To upload avatars i use this endpoint now: /rest/insight/1.0/avatar/upload

Example:

#!/bin/bash

# generate uid
uid=
$(uuidgen | tr "[:upper:]" "[:lower:]")

# upload picture
curl -v -H "X-Atlassian-Token: 'no-check'" -H "Authorization: Bearer <TOKEN>" -F file=@picture.jpg -F avatarUUID=$uid <BASE_URL>/rest/insight/1.0/avatar/upload

# set picture as avatar on object
curl -v -H "Content-Type: application/json" -H "X-Atlassian-Token: 'no-check'" -H "Authorization: Bearer <TOKEN>" -X PUT --data '{"attributes": [{"objectTypeAttributeId": <objectTypeAttributeIDtoUpdate>,"objectAttributeValues": [{"value": "<VALUE>"}]}],"objectTypeId": 1,"avatarUUID": "'$uid'","hasAvatar": true}' <BASE_URL>/rest/insight/1.0/object/<OBJECT_ID>

 

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events