It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to get license count for JIRA using REST API?

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

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

Does this work for jira cloud ?

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.

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

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!

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

334 views 1 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you