Hi Team,
how to get list of all projects, project name and project category name in Jira Data Center
or at least omit pagination on All project types - All categories page
In tests, the category shows in the endpoint: /api/2/project
You can use an test script in postman to retrieve all information in a table, the output looks like this:
Here the test script below:
const template = `
<style type="text/css">
.tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
.tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
.tftable tr {background-color:#ffffff;}
.tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
.tftable tr:hover {background-color:#e0ffff;}
</style>
<table class="tftable">
<thead>
<tr>
<th>Project ID</th>
<th>Project Name</th>
<th>Project Category</th>
<th>Project Type</th>
</tr>
</thead>
<tbody>
{{#each table}}
<tr>
<td>{{this.id}}</td>
<td>{{this.name}}</td>
<td>{{this.category}}</td>
<td>{{this.type}}</td>
</tr>
{{/each}}
</tbody>
</table>
`;
const body = pm.response.json(); // Jira API response
if (!Array.isArray(body)) {
console.error("Unexpected response format. Expected an array.");
pm.visualizer.set(`<h3 style="color:red;">Error: Unexpected response format</h3>`);
} else {
const table = body.map(project => ({
id: project.id,
name: project.name,
category: project.projectCategory ? project.projectCategory.name : "No Category",
type: project.projectTypeKey || "Unknown"
}));
// Set the visualizer with formatted data
pm.visualizer.set(template, { table });
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Endpoint is the same but the results are different. I see it in my browser now and that's why I asked this question :D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you please provide an example of the response you get in your rest api call?
Also, do you have Scriptrunner in your environment?
If you had, you can use some groovy solutions to retrive this information, here the groovy version of the solution above:
import com.atlassian.jira.component.ComponentAccessor
def projectManager = ComponentAccessor.getProjectManager()
def projects = projectManager.getProjectObjects()
def htmlTable = """
<style>
.tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
.tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
.tftable tr {background-color:#ffffff;}
.tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
.tftable tr:hover {background-color:#e0ffff;}
</style>
<table class="tftable">
<thead>
<tr>
<th>Project Id</th>
<th>Project Name</th>
<th>Project Type</th>
<th>Project Category</th>
</tr>
</thead>
<tbody>
"""
projects.each { project ->
def category = project.getProjectCategory()?.getName() ?: "No Category"
def projectType = project.getProjectTypeKey()?.getKey() ?: "No Type"
htmlTable += """
<tr>
<td>${project.getId()}</td>
<td>${project.getName()}</td>
<td>${projectType}</td>
<td>${category}</td>
</tr>
"""
}
htmlTable += """
</tbody>
</table>
"""
return htmlTable
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
this script works like a charm :) Thank you
but
api call is not working for me using API Browser Jira plugin:
[
{
"expand": "description,lead,url,projectKeys",
"self": "",
"id": "",
"key": "",
"name": "",
"avatarUrls": {
"48x48": "",
"24x24": "",
"16x16": "",
"32x32": ""
},
"projectTypeKey": "software",
"archived": false
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad to hear it works for you.
Not so sure about the API, but one cause can be the version of your jira application, who can affect the information the api retrieve.
If you need anything else, be free to ask.
Best Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually, I have one more similar problem I've been struggling with for some time. I'm trying to get a list of workflows (only active or all) like: workflow name and all statuses available in that particular workflow. Do you think it's also possible to get via API or scriptrunner?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, using the same template we use in project, it's possible create a workflow version:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.WorkflowManager
// Get the WorkflowManager
def workflowManager = ComponentAccessor.getWorkflowManager()
// Get all workflows
def workflows = workflowManager.getWorkflows()
def htmlTable = """
<style>
.tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
.tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
.tftable tr {background-color:#ffffff;}
.tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
.tftable tr:hover {background-color:#e0ffff;}
</style>
<table class="tftable">
<thead>
<tr>
<th>Workflow Name</th>
<th>Status</th>
<th>Workflow Status</th>
</tr>
</thead>
<tbody>
"""
workflows.each { workflow ->
def workflowname = workflow.name
def statuses = workflow.getLinkedStatusObjects().name ?: "No Status"
def workflowstatus = workflow.isActive() ? "Active" : "Inactive"
htmlTable += """
<tr>
<td>${workflowname}</td>
<td>${statuses}</td>
<td>${workflowstatus}</td>
</tr>
"""
}
htmlTable += """
</tbody>
</table>
"""
return htmlTable
Here an example of the output:
Let me know if this works for you.
Best Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This question has been answered perfectly for most part by @M Amine and @Fabio Racobaldo _Herzum_ in this forum. As you're on datacenter (as I am), you should be fine with the sql query. I built upon their foundation this query, which works fine for me.
use YOURJIRADB
select p.* , pc.cname as CategoryName from nodeassociation na
inner join project p on (p.ID = na.SOURCE_NODE_ID)
inner join projectcategory pc on (pc.ID = na.SINK_NODE_ID)
where na.ASSOCIATION_TYPE='ProjectCategory' and na.SOURCE_NODE_ENTITY='Project'
A big thank you to my peers, who opened my eyes regarding the nodeassociation table.
Link: Jira-questions/SQL-query-for-Project-name-category-and-workflow/qaq-p/775264
Kind regards,
Dick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
/project/type returns just types of projects in jira, which is irrelevant.
/project is missing category that's why I asked this question
------------------------------------
Nikola Perisic mentioned you in
Get list of all projects, project name and category name
Hi Chamdarig Dall
Project types API that can be retrieved - /api/2/project/type
Getting all visible projects API as well - /api/2/project
More APIs could be found here: https://developer.atlassian.com/server/jira/platform/rest/v10002/api-group-project/#api-group-project
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.