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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do I get a list of labels with C#

How do I get a list of labels for a Jira server with C#?

I can get a list of projects with

jira.Projects.GetProjectsAsync();

a list of components for a project with:

jira.Components.GetComponentsAsync(project);

Is there an API to get a list of labels? Per project or global?

2 answers

1 accepted

0 votes
Answer accepted
Warren Community Leader Dec 22, 2020

Hi @Pete Goodwin 

As per the version 3 API documentation there is a call to get the global labels.

Hope this helps

Thanks, that got me a global list of labels. Any way to get a list of labels per project?

Warren Community Leader Dec 22, 2020

Hi @Pete Goodwin 

That's known as Scope Creep - your question said either per project or global, I give you global but you actually want per project  ;-)

Seriously, no I can't see a way to limit it to a project, the only parameters it takes is startAt and maxResults 

Hi @Pete Goodwin ,

You can use the REST API endpoint for GET /rest/api/3/label as the first step.  But again as @Warren noted, this just gives you back the labels across all projects.

However, once you can see the names of these labels, you can put these into a JQL search via REST for each label name to the endpoint GET /rest/api/2/search

I do not have a working example in C# but in theory, as an example, a call formatted something like the following, where this will return all the issues that use a specific label and then order the results by their project.  From there you could then take that data to match out the project value per issue or the issue key of the issues returned to see which projects are using this:

GET /rest/api/2/search?jql='labels in (label1,label2,label3,.....etc) order by project desc'

OR the following which would isolate to the specified project, and return any issues with labels in use from your list of all labels, which could then be grouped to show unique labels for your list per project in yor script. 

GET /rest/api/2/search?jql='labels in (label1,label2,label3,.....etc) AND project = EXE'

Hope this helps

Regards,
Earl

I've discovered there are 3000+ labels globally, so can that work with labels in (x, y, z...)?

Hi @Pete Goodwin ,

Long URL's can hit memory issues in the browser but I do not believe you would run into any limitation in the API and would allow for much longer input strings.  The only downside is that manual input would be unmanageable as the labels can be added in ad-hoc so constant watching for updates would be needed.  Going this route I would suggest looking into a method to script the input values into the second query from the first.

Another option for this would be a front-end method and use the Labels Gadget.  Drop the labels gadget onto a dashboard, set to project and labels and it will populate a list of labels used in that particular project.  Unfortunately in this approach, the data is returned in the gadget is using a client-side javascript to process the information in the browser so there is not an option to automate pulling the data out of the gadget via the API, but it would dramatically reduce the footprint by isolating the lists to the specified projects and reduce overhead on the input manual approach.

Regards,
Earl

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
Community showcase
Published in Jira

Announcing the waitlist for Jira Work Management

Hey there Cloud Community members! We’re excited to give you the first glimpse of the new home for business teams on Jira — Jira Work Management. Jira Work Management is the next generation of J...

880 views 14 20
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you