The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira REST API for configuring dashboard gadget

EddieCM_Chuang
July 16, 2022

My goal is to create dashboard gadgets automatically and programatically. I tried to create dashboard gadget, filter results, using jira rest api. However, there isn't any parameters to set 'saved filter', 'Number of results' or 'Columns to display' for gadget in api ('add gadget to dashboard', 'update gadget to dashboard'). The only thing I can do with api is create an empty gadget.
How can I configure gadgets using api? If it isn't possible, any alternative solution or workaround?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

2 votes
Answer accepted
Fabio Racobaldo _Catworkx_
Community Champion
July 16, 2022

Hi @EddieCM_Chuang ,

welcome to the Atlassian community!

You should use the following rest api https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-dashboards/#api-rest-api-3-dashboard-dashboardid-items-itemid-properties-propertykey-put in order to setup a gadget on a dashboard using api.

Hope this helps,

Fabio

EddieCM_Chuang
July 16, 2022

Thanks a lot! I will study the dashboard item.

I'm curious about why Jira provides the rest api to add/update gadgets, but not to configure gadgets.

Arun
January 4, 2024
Hi @Fabio Racobaldo _Herzum_

import
ForgeUI, { render, Fragment, Macro, Text, useState } from "@forge/ui";
import api, { route } from "@forge/api";

const getDashoardDetails = async () => {
  var bodyData = `{
    "description": "A dashboard to help auditors identify sample of issues to check.",
    "editPermissions": [],
    "name": "Auditors dashboard",
    "sharePermissions": [
      {
        "type": "global"
      }
    ]
  }`;
 
  const response = await api.asUser().requestJira(route`/rest/api/3/dashboard`, {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    body: bodyData
  });
 
  console.log(`Response: ${response.status} ${response.statusText}`);
  console.log(await response.json());
}

const App = () => {
  const dashboards = useState(async () => await getDashoardDetails());
  console.log('--> dashboardDetails', dashboards);

  return (
    <Fragment>
      <Text>Hello world!</Text>
    </Fragment>
  );
};

export const run = render(
  <Macro
    app={<App />}
  />
);

my forge app code is here am trying to create a dashboard on forge app here am facing some issues on server after deployed on server it returning an null value on the logs

[ null, "[Function]" ]
1 vote
EddieCM_Chuang
July 16, 2022

Thanks for @Fabio Racobaldo _Catworkx_ suggestion.

My python implementation using jira api `set dashboard item properties`.

payload = json.dumps({
    "filterId": "10711",
    "num": "50",
    "columnNames": "issuetype|summary|issuekey",
    "refresh": "true",
    "isConfigured": "true"
})

res = requests.request(
    "PUT",
    f"{HOST}/rest/api/3/dashboard/{dashboard_id}/items/{item_id}/properties/config",
    headers={
        "Accept": "application/json",
        "Content-Type": "application/json"
    },
    data=payload,
    auth=HTTPBasicAuth(EMAIL, TOKEN)
)
Fabio Racobaldo _Catworkx_
Community Champion
July 16, 2022

you're welcome @EddieCM_Chuang