Create new key while create project by API

HI All,

          How will get all project keys. Because while we create new project by API  i need to give different key. So before that i need to check all existing Key and create new Key. How will achieve this?

2 answers

1 vote
Vasiliy Zverev Community Champion Jan 14, 2016

Since you have a collection on project keys for each project you have to do a loop over all projects. Here is a code example how to get all project keys:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager

ProjectManager projectManager = ComponentAccessor.getProjectManager();

List<String> prjKeys = new ArrayList<>();

for(Project project: projectManager.getProjectObjects()){
    prjKeys.addAll(projectManager.getAllProjectKeys(project.getId()))
}

return prjKeys.toString()

can you please share your code.. I'm also working on something related to this

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Asked Thursday in Jira Ops

I'm John Allspaw, Ask Me Anything about incident analysis and postmortems

I'm John Allspaw, co-founder of   Adaptive Capacity Labs, where we help teams use their incidents to learn and improve. We bring research-driven methods and approaches to drive effective inciden...

5,382 views 21 17
View question

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you