Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

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

How to get license count for JIRA using REST API?

Chander Inguva
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.
June 19, 2018

I was working on a script to automate the license count for JIRA Software (Server), also send an email everyday about the count of licenses.

 

2 answers

4 votes
Chander Inguva
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.
June 19, 2018 edited

Hope this script helps someone looking for a solution to count jira licenses 

I have used basic Python requests module for this. Tweak the code for your own use.

 

#Package for REST API CALL and json formatting
import requests
import json

#Packages for Email
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders

headers = { 'Accept': '*/*',}
url= 'https://jira.example.com/rest/plugins/applications/1.0/installed/jira-software'
r=requests.get(url=url,headers=headers,auth=("username","password"),verify=False)
print(r.status_code)
data=json.loads(r.text)
activeUsers = data['accessDetails']['activeUserCount']
#print("There are currently %d counted towards JIRA Software License" % (activeUsers))licensedUsers = data['accessDetails']['licensedUserCount']
remainingLicenses= licensedUsers - activeUsers
#print("There are %d licenses left" % (remainingLicenses))

#Send Email
recepients=['user1@example.com']
fromaddr="user2@example.com"
msg=MIMEMultipart()
msg['From']=fromaddr
msg['To']=", ".join(recepients)
msg['Subject']="JIRA License Information"   
body="There are currently" + " " +str(activeUsers)+ " "+ "accounts counted towards JIRA Software License [2000 User License]"
msg.attach(MIMEText(body,'plain'))
server=smtplib.SMTP('smtp.example.com',25)
text=msg.as_string()
server.sendmail(fromaddr,recepients,text)
server.quit()

 Ref: https://stackoverflow.com/questions/24077314/how-to-send-an-email-with-style-in-python3

 

 

Email Screenshot

JiraLicenseInfoMail.PNG

Hope this helps getting started.

Thank You

Chander Inguva

Krishna m
Contributor
August 6, 2018

Does this work for jira cloud ?

Chander Inguva
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.
August 8, 2018

Hey Krishna,

Please try setting the URL to Jira Cloud, unfortunately i do not have a cloud instance to check it.

I believe it should work.

Jerry Laster _Divim_ Inc__
Atlassian Partner
October 1, 2019

This doesn't seem to work anymore. The url is no longer valid. Anyone found a different approach?

Christian Bär
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.
August 7, 2020

Still works for Server

0 votes
Julia Nunes Pedrosa
Contributor
August 20, 2018

Hello Chander, 

I haven't tried this script yet but I'm whiling to do it right now and would like to thank you even before actually trying it out. 

Thank's for sharing this!

Irfan Ansari February 16, 2020

This api doesn't work now.

Any other solution.?

 

Thanks,

Irfan Ansari

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Upcoming Jira Events