How do I get a list of labels with C#

Pete Goodwin December 21, 2020

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
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.
December 22, 2020

Hi @Pete Goodwin 

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

Hope this helps

Pete Goodwin December 22, 2020

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

Warren
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.
December 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 

0 votes
Earl McCutcheon
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 22, 2020

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

Pete Goodwin December 22, 2020

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

Earl McCutcheon
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 30, 2020

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
AUG Leaders

Atlassian Community Events