Using Team capacity from Jira Plans
Asked by Maria Del Rosario Gonzalez:

I would like to display the Team capacity value defined in Jira Plans on a Confluence page that lists out all teams within our portfolio.

Is there a way to display perhaps via smart values? I have reviewed the documentation and don't see anything that would point me in the right direction.

Thanks in advance!


Answers:
author: Maria
body: Hi [@Maria Del Rosario Gonzalez](/t5/user/viewprofilepage/user-id/5002206)

Displaying the team capacity value defined in Jira Plans on a Confluence page is a bit tricky because there isn't a direct out-of-the-box integration for this specific requirement using smart values. However, you can achieve this through a combination of Jira and Confluence functionalities along with some custom scripting. Here's a step-by-step guide to get you started:

### Step 1: Fetch Team Capacity from Jira {#toc-hId-2142712945}

You will need to fetch the team capacity data from Jira using the Jira REST API. You can write a script (in Python, for example) to fetch this data.

1. **Get Team Capacity from Jira API:**
   * Use the Jira REST API endpoint to get the team capacity. You might need to authenticate and make a GET request to the API endpoint that provides team capacity data.

### Step 2: Create a Page in Confluence {#toc-hId-335258482}

Next, you can use the Confluence REST API to create or update a Confluence page with the fetched team capacity data.

1. **Create/Update Confluence Page:**
   * Use the Confluence REST API to create or update a page. You'll need to format the data in a way that it displays correctly on the Confluence page.

### Step 3: Automate the Process {#toc-hId--1472195981}

To automate this process, you can set up a script to run at regular intervals, fetch the latest team capacity data from Jira, and update the Confluence page.

### Example Script (Python) {#toc-hId-1015316852}

Here's a simplified example of how you might write a Python script to achieve this:  

import requests  
import json

# Define your Jira and Confluence credentials and URLs  
JIRA_URL = '<https://your-jira-instance.atlassian.net>'  
CONFLUENCE_URL = '<https://your-confluence-instance.atlassian.net>'  
JIRA_API_ENDPOINT = '/rest/api/3/path-to-team-capacity-endpoint'  
CONFLUENCE_API_ENDPOINT = '/wiki/rest/api/content/'  
JIRA_USERNAME = 'your-jira-username'  
JIRA_API_TOKEN = 'your-jira-api-token'  
CONFLUENCE_USERNAME = 'your-confluence-username'  
CONFLUENCE_API_TOKEN = 'your-confluence-api-token'

def get_team_capacity():  
headers = {  
'Accept': 'application/json',  
'Content-Type': 'application/json'  
}  
response = requests.get(f"{JIRA_URL}{JIRA_API_ENDPOINT}", auth=(JIRA_USERNAME, JIRA_API_TOKEN), headers=headers)  
return response.json()

def update_confluence_page(content):  
headers = {  
'Authorization': f'Basic {CONFLUENCE_API_TOKEN}',  
'Content-Type': 'application/json'  
}  
data = {  
'type': 'page',  
'title': 'Team Capacity',  
'space': {'key': 'YOUR_SPACE_KEY'},  
'body': {  
'storage': {  
'value': content,  
'representation': 'storage'  
}  
}  
}  
response = requests.post(f"{CONFLUENCE_URL}{CONFLUENCE_API_ENDPOINT}", auth=(CONFLUENCE_USERNAME, CONFLUENCE_API_TOKEN), headers=headers, data=json.dumps(data))  
return response.json()

def format_content(data):  
content = "\<h2\>Team Capacity\</h2\>\<table\>\<tr\>\<th\>Team\</th\>\<th\>Capacity\</th\>\</tr\>"  
for team in data\['teams'\]:  
content += f"\<tr\>\<td\>{team\['name'\]}\</td\>\<td\>{team\['capacity'\]}\</td\>\</tr\>"  
content += "\</table\>"  
return content

if __name__ == "__main__":  
team_capacity_data = get_team_capacity()  
formatted_content = format_content(team_capacity_data)  
update_confluence_page(formatted_content)  

### Notes: {#toc-hId--792137611}

1. **Authentication:** Replace the placeholders with your actual Jira and Confluence credentials.
2. **Endpoints:** Update the API endpoints according to your Jira and Confluence instance URLs.
3. **Error Handling:** Add appropriate error handling and logging to the script.
4. **Automation:** Schedule this script to run periodically using a cron job or another scheduling tool.  

If you're looking for an easier way, try [Planyway addon for Jira](https://marketplace.atlassian.com/apps/1221297/planyway-resource-planning-project-roadmap-time-tracking?tab=overview&utm_campaign=atlassianquestions&utm_medium=referral&utm_source=atlassiancommunity&hosting=cloud).

The Planyway app for Jira can be a helpful tool for visualizing and managing your team's capacity and workload. It provides a user-friendly interface for planning and tracking projects, making it easier to manage resources and timelines.![Workload Planner](https://files.planyway.com/assets/3.0.573/img/jira/cases/workload-planner.png)

comments: author: Maria Del Rosario Gonzalez
body: Thank you for your answer!


Tags: cloud

jira-cloud