Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to retrieve the project key by project id through the java API?

Andrey Luiz July 2, 2015

Hello.

I need to get the project key (or keys) programmatically.

The only alternative to retrieve the project keys I found was the content on this page:

https://confluence.atlassian.com/display/JIRA/Editing+a+Project+Key#EditingaProjectKey-Notesfordevelopers

There it says:

  • Get all project keys: com.atlassian.jira.project.ProjectManager#getAllProjectKeys

What I need is to retrieve the key(s) by project id. Is there an easy way to do this? How can I know which key correspond to which project id?

I'm using Jira version 6.4.3 and Atlassian Plugin SDK version 5.0.13.

I am using the SAL Services. If someone have a better option, I'll be very grateful.

Thank's.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Andreas Ebert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 2, 2015

Well, your post already contains the answer to your question: Use com.atlassian.jira.project.ProjectManager#getAllProjectKeys

Is there any reason to not use that method? Or do you want to achieve something different?

 

Andrey Luiz July 2, 2015

Like I explained, I need the project keys by project id, got it?

Andreas Ebert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 2, 2015

No, I guess I don't get it. From the description in your initial post I still think that that method does exactly what you want, which is as I understood it: Given a project id, find all keys which are or were in use for the project with that id.

Like jimsander likes this
pelizza
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 2, 2015

Hi Andreas, I'm working with Andrey on this... Actually, you are right! We couldn't find this method before because we were using the "com.atlassian.sal.api.ProjectManager" class that, in spite of having the same name, doesn't have such method. Thanks!

1 vote
GabrielleJ
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 2, 2015

Have you tried getting it via the JIRA Database or JIRA REST API per project?.

https://developer.atlassian.com/jiradev/jira-architecture/database-schema

https://docs.atlassian.com/jira/REST/latest/

Andrey Luiz July 2, 2015

I don't believe I'll be able to get this info from the database. I can only access my plugin stuff, I guess. And the REST API does not apply to this case because I'm in the back end. In the front-end I can get it for sure. Another suggestion?

Daniel Wester
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 2, 2015

In case somebody comes in after this. Don't go through the database layer from inside a jira plugin. You'll get hurt (caching, database connections etc). Stay in the java jira api and you'd be good (I'm also not a fan of the web making rest calls out and into itself - it's as security issue waiting to happen).

TAGS
AUG Leaders

Atlassian Community Events