How to obtain {ItemId} in api/2/dashboard/{dashboardId}/items/{itemId}/properties

anil February 21, 2017

We are getting the dashbords list in json with "api/2/dashboard/{dashboardId}".

In one of the dash board it has lot of graphs there. Now, is there any way we can try to pull the values of each graph ? 

 

Next, what is  'items' and itemid in the dashboard URL . How can we identify values ? How to  obtain {ItemId} in api/2/dashboard/{dashboardId}/items/{itemId}/properties.

5 answers

1 vote
David Kleňha November 28, 2017

There is no possibility to find out the itemid from API. Only way I find the itemid is from source code of page. 

<div class="dashboard-item-frame gadget-container" id="gadget-17972-chrome">

 "17972" is the itemid.

 

I'm not sure when this ID is changed and if it'll stay the same all the time... but at least there is some way how to find it out.

0 votes
Andrey Tetyuev March 12, 2024

Hi together,
It seems that the REST API of JIRA server edition doesn't allow to retrieve the Dashboards-content easily (and the support & further development for server edition seems to be stopped, so I would not expect that such API will appear for server in future).
At same time - the cloud version of JIRA has REST API interface to work with Dashboards .

However there is trick - how to get details about Dashboards even for server version (see description below). The trick doesn't use REST API directly, but retrieves JIRA-internal types/IDs (so with retrieved information - further actions could be performed via REST-API).
Use-case example: retrieve Dashboards information from old (server) JIRA and add the Dashboards to new (cloud) JIRA by JIRA migration.

1) Get the list of Dashboards with their IDs (if you have more than 1000 dashboards (respect ;-) ) - you might need to increase the limit or iterate over subsets of dashboards):

https://YOUR_SERVER/rest/api/2/dashboard/?maxResults=1000


For each Dashboard you will get:

id   (e.g. 12345)
name   (e.g. "My Dashboard")
self    (a REST API link to the dashboard, e.g. "https://YOUR_SERVER/rest/api/2/dashboard/12345" )
view   ( a link to user-view of the dashboard, e.g. "https://YOUR_SERVER/secure/Dashboard.jspa?selectPageId=12345" )

2) Get gadgets and layout of certain dashboard(s).
The REST API view of dashboard doesn't provide more details. Also by user-view - the elements/content being generated/shown dynamically (via plugins/scripts), so you can't get them by parsing the page. However there is alternative "user-related" Wallboard view of the dashboard available, which contains gadgets details inside html-code:

https://YOUR_SERVER/plugins/servlet/Wallboard/?dashboardId=12345

The html code of such view includes javascript, which has a list of used gadgets with their configuration (partly as separate attributes, partly within corresponding gadget-url). Also some details about dashboard-layout are available.
For example the attribute:

column: 'wallframe-N-column-M'

indicates the frame N and column M of current gadgets-subset (in my case - the frame was always 0 and the column had a number 0 or 1 by dashboard-layout with 2 columns).

Also each gadget might have extra column-number argument, e.g.:

column: '#column-0'

The information about gadget type, used filter-ID, etc. is available as parameters of gadget-url, so you can parse it to get the gadget-configuration.
Here is the example of such url:

url: "https://YOUR_SERVER/plugins/servlet/gadgets/ifr?container=atlassian&mid=67890&country=US&lang=en&view=default&view-params=%7B%22writable%22%3A%22true%22%7D&st=atlassianAUTHENTICATION_TOCKEN&up_type=filter&up_id=22222&up_operation=count&up_isConfigured=true&up_isPopup=false&up_refresh=15&up_projectOrFilterId=&up_daysprevious=90&up_periodName=weekly&up_versionLabel=none&up_isCumulative=false&up_showUnresolvedTrend=false&url=https%3A%2F%2FYOUR_SERVER%2Frest%2Fgadgets%2F1.0%2Fg%2Fcom.atlassian.jira.gadgets%3Acreated-vs-resolved-issues-chart-gadget%2Fgadgets%2Fcreatedvsresolved-gadget.xml&libs=auth-refresh"

Let check some parameters of the url:

&mid=67890    // REST API ID of the gadget (using 67890 as example)
&country=US
&lang=en
&view=default
&st=atlassianAUTHENTICATION_TOKEN    // authentication token used when the Wallboard-view was opened (needed for gadget itself, might get outdated after while). Note: there is some prefix between word "atlassian" and token itself, but to keep it simple - I've named it all as token
&up_type=filter   // the gadget uses JIRA-filter
&up_id=22222   // the filter-ID (using 22222 as example)
&up_operation=count
&up_isConfigured=true
&up_isPopup=false
&up_refresh=15    // refresh the gadget each 15 minutes
&up_projectOrFilterId= // not used by current gadget configuration (i.e. empty)
&up_daysprevious=90    // consider only Issues within last 90 days (returned by the filter)
&up_periodName=weekly    // group/display Issues on timeline on weekly base
&up_versionLabel=none
&up_isCumulative=false   // don't use cumulative kind of view
&up_showUnresolvedTrend=false   // don't show trend of unresolved issues
&url=https%3A%2F%2FYOUR_SERVER%2Frest%2Fgadgets%2F1.0%2Fg%2Fcom.atlassian.jira.gadgets%3Acreated-vs-resolved-issues-chart-gadget%2Fgadgets%2Fcreatedvsresolved-gadget.xml    // see below
&libs=auth-refresh

The parameter url within gadget-url (see above) defines the type of the gadget:
So if you would search for the RegEx:

"com\.atlassian\.jira\.gadgets%3A([^ \"]+gadget)\.xml"

- you would get the "subpath" and name of the gadget-type (html-encoded) within 1st match-group of the RegEx, e.g.:

  • average-age-chart-gadget/gadgets/average-age-gadget
  • created-vs-resolved-issues-chart-gadget/gadgets/createdvsresolved-gadget
  • filter-results-gadget/gadgets/filter-results-gadget
  • project-gadget/gadgets/project-gadget
  • stats-gadget/gadgets/stats-gadget
  • time-since-chart-gadget/gadgets/timesince-gadget
  • two-dimensional-stats-gadget/gadgets/two-dimensional-stats-gadget
  • etc.

Additional hint: if you open the complete gadget-url separately - you will get the user-view content of this gadget (however again - only as dynamical-view, so the values will not be visible in html-code)

Summary: via Wallboard-view of dashboard you can get list of gadgets with their types, location within dashboard-layout, used filters and further configuration parameters.

Hope - it helps to someone.

0 votes
Peter Shi December 12, 2021

 Recently I found some weird pattern in dashboard html... The gadget ID always show twice in the original html. So I wrote these codes to fetch gadget ID from a dashboard. Hope this will help you :)

def initLink(method,url,auth,headers,payload):
response = requests.request(
method,
url,
headers=headers,
auth=auth,
data=payload
)
return response

def getHtml(dashboardId):
url = "https://your-domain.atlassian.net/jira/dashboards/"+dashboardId
headers = {
"Accept":"application/json"
}
response = initLink("GET",url,auth,headers,"")
return response.text

def generateGadgetList(dashboardId):
html = getHtml(dashboardId)
gadgetPat = re.compile("\"id\":\"(\d{5})\"")
gadgetList = gadgetPat.findall(html)
count = {}
result = []
for gadget in gadgetList:
if gadget in count.keys():
count[gadget]+=1
else:
count[gadget]=1
for key,value in count.items():
if value==2:
result.append(key)
return result
Kargo Tech Comms June 16, 2022

Thanks for the script. 

I had to make a few changes to it for our API access but otherwise it worked perfectly. My slightly modified script: 

import requests
import re

def initLink(method,url,auth,headers,payload):
response = requests.request(
method,
url,
headers=headers,
auth=auth,
data=payload
)
return response

def getHtml(dashboardId):
url = "https://kargo1.atlassian.net/jira/dashboards/"+dashboardId
myHeader = {'Authorization': 'Basic a3RjQGthcmdvLmNvbTpldVFvbXhwd3RtaGpBUUh1UW10VDVBNjQ=', 'Content-Type': 'application/json'}
results = requests.get(url, headers=myHeader)
return results.text

def generateGadgetList(dashboardId):
html = getHtml(dashboardId)
gadgetPat = re.compile("\"id\":\"(\d{5})\"")
gadgetList = gadgetPat.findall(html)
count = {}
result = []
for gadget in gadgetList:
if gadget in count.keys():
count[gadget]+=1
else:
count[gadget]=1
for key,value in count.items():
if value==2:
result.append(key)
return result

#+++++++++++++++++++++++++++++++++++++++++
# PROGRAM STARTS HERE
#+++++++++++++++++++++++++++++++++++++++++

arrGadets = generateGadgetList("14726")


 

0 votes
Lara Arthur May 11, 2021

I know this post is super old, but....I believe I found a way to get the dashboard/gadget id's using ScriptRunner.

This script comes from their how to automatically create a Dashboard...

Go to your SR console and add the following script...only thing you'll need to update is the Dashboard ID you want to get the info from

import com.atlassian.jira.bc.JiraServiceContext
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.bc.portal.PortalPageService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.portal.PortletConfiguration
import groovy.json.JsonOutput
import groovy.xml.MarkupBuilder

def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
JiraServiceContext sourceUserServiceCtx = new JiraServiceContextImpl(user)
def portalPageService = ComponentAccessor.getComponent(PortalPageService)

//your dashID is equal to your PageID url - the number it provides
def dashId = 19300

def output = portalPageService.getPortletConfigurations(sourceUserServiceCtx, dashId).collect { col ->
col.collect { PortletConfiguration gadget ->
[

//by chance...added this...and it works!
id : gadget.id,
//the script below is directly from SR how to's
row : gadget.row,
column : gadget.row,
color : gadget.color,
openSocialSpecUri: gadget.openSocialSpecUri.getOrNull().toString(),
completeModuleKey: gadget.completeModuleKey.getOrNull().toString(),
userPrefs : gadget.userPrefs,
]
}
}

def prettyOutput = JsonOutput.prettyPrint(JsonOutput.toJson(output))
log.debug(prettyOutput)

def writer = new StringWriter()
def builder = new MarkupBuilder(writer)
builder.pre(prettyOutput)
writer

 When you run the code above, you get:

[
[
{
"id": 24200,
"row": 0,
"column": 0,
"color": "color1",
"openSocialSpecUri": "rest/gadgets/1.0/g/com.atlassian.jira.gadgets:text-gadget/gadgets/text-gadget.xml",
"completeModuleKey": "null",
"userPrefs": {
"isConfigured": "true",
"refresh": "false",
"html": "var gadget = AJS.Gadget({\r\n...\r\n\tview: {\r\n\t\t...\r\n \ttemplate: function (args) {\r\n\t\t\t...\r\n\t\t\tvar gadgetId = this.getPrefs().getModuleId();\r\n\t\t\t...\r\n\t\t}\r\n\t}\r\n...\r\n});",
"title": ""
}
},
Joshua Cheung June 7, 2021

Hi Lara, thanks for your answer! Do you know if this would be possible to do without the use of script runner? 

Lara Arthur June 24, 2021

@Joshua Cheung - If you can chat with a System Admin who knows their way around Jira...maybe from the backend? Not 100% sure, but I don't believe that it's possible any other way from the front end.

Like Joshua Cheung likes this
0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 21, 2017

From the docs-

A dashboard item is similar to a gadget, in that it provides discrete dynamic content that a user can use to customize their dashboard. However, dashboard items use modern rendering technologies like AMD, Soy, LESS, etc. Dashboard items are also able to share web-resources, which greatly improves page load performance by reducing the number of requests and the overall size of data to be transferred on a dashboard load.

Currently, it doesn't seem possible to fetch list of items of dashboard using REST API, similar question here -

https://answers.atlassian.com/questions/39553910

 

In the latest API documentation - https://docs.atlassian.com/jira/REST/server/#api/2/dashboard-list 

There is no method getting dashboard item list, something like - GET /rest/api/2/dashboard/{dashboardId}/items/ 

anil February 21, 2017

Hi Tarun,

what data we need to pass in 'itemid' in URL which is under 'dashboard/items'.

Say for example : one of the  dash board has a single Pie Gadget.

Now, what I need to pass a value for an itemid in 'api/2/dashboard/{dashboardId}/items/{itemId}/properties' URL ?

Please provide an answer.

 
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 21, 2017

I will suggest you to create your own REST end point using the script runner plugin or the REST plugin module and use the Java API of the script runner to fetch the details of the dashboard gadgets.

Like babytree likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events