Skip to main content
Background Image
  1. Posts/

Update Jira server account avatar with rest API

·185 words·1 min· ·
Xianpeng Shen
Author
Xianpeng Shen
Table of Contents

Backgroud
#

When you are using a server account for CI/CD, if you want to make the server account avatar to looks professional on Jira update but the server account may not allowed to log to Jira, so you can not update the avatar though GUI, you could use Jira REST API to do this.

I assume you have an account called robot, here are the examples of how to update though REST API.

Example in Python
#

import http.client

conn = http.client.HTTPSConnection("jira.your-company.com")

payload = "{\r\n\t\"id\": \"24880\",\r\n\t\"isSelected\": false,\r\n\t\"isSystemAvatar\": true,\r\n\t\"urls\": {\r\n\t\t\"16x16\": \"https://jira.your-company.com/secure/useravatar?size=xsmall&avatarId=24880\",\r\n\t\t\"24x24\": \"https://jira.your-company.com/secure/useravatar?size=small&avatarId=24880\",\r\n\t\t\"32x32\": \"https://jira.your-company.com/secure/useravatar?size=medium&avatarId=24880\",\r\n\t\t\"48x48\": \"https://jira.your-company.com/secure/useravatar?avatarId=24880\"}\r\n}"

headers = {
    'content-type': "application/json",
    'authorization': "Basic Ymx3bXY6SzhNcnk5ZGI=",
    'cache-control': "no-cache",
    'postman-token': "ecfc3260-9c9f-e80c-e3e8-d413f48dfbf4"
    }

conn.request("PUT", "/rest/api/latest/user/avatar?username=robot", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

Example in Postman
#

# URL and Method is PUT
https://jira.your-company.com/rest/api/latest/user/avatar?username=robot

# Authorization
# Type: Basic Auth
# Username: server-account-username
# Password: server-accoutn-password

# Body
{
	"id": "24880",
	"isSelected": false,
	"isSystemAvatar": true,
	"urls": {
		"16x16": "https://jira.your-company.com/secure/useravatar?size=xsmall&avatarId=24880",
		"24x24": "https://jira.your-company.com/secure/useravatar?size=small&avatarId=24880",
		"32x32": "https://jira.your-company.com/secure/useravatar?size=medium&avatarId=24880",
		"48x48": "https://jira.your-company.com/secure/useravatar?avatarId=24880"}
}

How to find the avatar id
#

You replace other avatar ids you like. Here is how to find you avatar id you want

find avatar id

Related

Fixed "Remote session was disconnected because there are no Remote Desktop client access licenses available"
·152 words·1 min
Fix the RDP connection issue on Windows Server 2012 R2, where the error message indicates that there are no Remote Desktop client access licenses available.
Daily Notes
·1848 words·9 mins
Starting August 7, 2020, I would like to start recording some daily/important things in English.
How to fix ".NET Framework 2.0 or later is required on this computer to run a Jenkins agent as a Windows service"
·211 words·1 min
Resolve the issue of Jenkins Windows agents not connecting due to missing .NET Framework, including steps to install .NET Framework 3.5 and set up the Jenkins agent service.
Jenkins Top 3 best practice
·906 words·5 mins
Discusses three best practices for Jenkins: Configuration as Code, Shared Libraries, and Multi-Branch Pipeline, highlighting their benefits in terms of transparency, traceability, and self-service builds.
How to use JMeter to do Performance Testing
·491 words·3 mins
A guide on using JMeter for performance testing, including recording scripts, running tests in GUI and non-GUI modes, and integrating with Jenkins for automated testing.
Bitbucket Webhooks Configuration
·398 words·2 mins
How to configure Bitbucket webhooks to trigger Jenkins builds for multi-branch pipelines, ensuring that Jenkins can automatically respond to events like pull requests and branch updates.