How to show project status based on number of issues
Asked by Rahul Banerjee:

We use JIRA cloud in BT.

Based on the number of issues in a project, I want to show assign a colored status / label in Confluence page. How do I do it ?

E.g. If no of issues with project "XYZ" is greater than 5, I want to have a status / label with a RED indicator on top of a confluence page


Answers:
author: Diego
body: Hello there Rahul!  
Currently, Confluence Cloud **does not have** a native method or macro to achieve this result. However, some **REST calls** can be used to perform this change.   

The first step would be to **create a page** with a **status macro** and also the J**ira issues macro** with **only one issue** from the desired project. With the status macro, we will be able to control the color of it later.  

After creating the page, it is time to GET the page content via REST:

**[REST API - GET content](https://developer.atlassian.com/cloud/confluence/rest/#api-content-get)**

This will allow us to get **two sets of data** , the **project key** from the issue macro and also the **status macro data** . The numbers and dash (-) should be**removed** from the string so we can use the key only:
> \<p\>\<ac:structured-macro ac:name="jira" ac:schema-version="1" ac:macro-id="6f3f1181-9671-410c-90c4-a754f37523a2"\>\<ac:parameter ac:name="server"\>JIRA\</ac:parameter\>\<ac:parameter ac:name="serverId"\>9de8af3e-0937-3d4b-8e79-933a2124cd43\</ac:parameter\>\<ac:parameter **ac:name="key"\>WAG-11**\</ac:parameter\>\</ac:structured-macro\>\</p\>

The value we need is under the **ac:name="key"** parameter.

Then, we need to check the **number of issues** for this specific project:

**[REST Client - get all issues of a project](https://community.atlassian.com/t5/Jira-questions/REST-Client-get-all-issues-of-project/qaq-p/494826)**

The reply from [Sayeed Ahmed](https://community.atlassian.com/t5/user/viewprofilepage/user-id/1627313) is actually the one we are looking into right now. Using the key found under the issue macro we will be able to know how many issues the project has.

Lastly, we need to **update the page content** we got earlier to reflect the changes, based on the number of issues returned:

**[REST API - PUT content](https://developer.atlassian.com/cloud/confluence/rest/#api-content-id-put)**

For this, you will need to change two parts of the status macro, the**ac:name="title"** parameter and also **ac:name="colour"** parameter:
> \<p\>\<ac:structured-macro ac:name="status" ac:schema-version="1" ac:macro-id="ecd9b86f-ac08-43b4-b1d5-800900b291f1"\>\<ac:parameter **ac:name="colour"\>Red** \</ac:parameter\>\<ac:parameter **ac:name="title"\>**DONE\</ac:parameter\>\</ac:structured-macro\>\</p\>

This change will be **based of on the arbitrary set of rules** you created. Your code for this script need to have this "hardcoded" or to fetch this list of rules from somewhere else.   
The reason that all these steps should be scripted is to **avoid executing those calls manually** after a given time interval. You can create this script using python, for example.   

Let us know if this helps out your objective!

comments: author: Rahul Banerjee
body: Thanks Diego for coming back on this.

I'm not a developer rather a super user in my company and trying to build a utility which shows project RAG which should automatically update its color based on issue number.

I'm going through the above recommendation step by step.

Could you pls tell me where can I invoke the REST API on my confluence page.

My current position is both macros are added - I've added a status and one-issue from a project.


author: Sandeep Srinivasan
body: where you able to do this?


Tags: atl-adm

jira