Insight Rest API: Object Avatar Upload

Christian Burger
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 7, 2018

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
Alexander Weickmann
Contributor
November 26, 2019
  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
}
Christian Burger
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 27, 2019

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.

Alexander Lackner March 22, 2022

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
AUG Leaders

Atlassian Community Events