Hi Community,
Please guide on how generate a list of existing labels present in Jira Software (Data Center) via API call.
It will be a great help you could share necessary help document and syntax code to generate the same via API call.
Thanks
Hi @Digvijay Singh Gehlot
In Jira Data Center, there is no native REST API endpoint that directly provides a list of all existing labels. However, there are some alternatives to obtain this information.
You can use the issue search REST API (/rest/api/2/search) and extract the labels from the results.
Endpoint:
/rest/api/2/search?jql=labels IS NOT EMPTY&fields=labels&maxResults=1000
Example of Usage with cURL
curl -u "seu_usuario:seu_token" -X GET \"https://SEU_JIRA_URL/rest/api/2/search?jql=labels IS NOT EMPTY&fields=labels&maxResults=1000" \-H "Content-Type: application/json"
I hope this helps you.
Best Regards.
@Digvijay Singh Gehlot
Below is a pseudo code that you could use
Use below jql and narrow it down as much possible say by adding condition like statusCategory != Done
then use below rest end point
url = "<a href="https://your-domain.atlassian.net/rest/api/3/search/jql" target="_blank" rel="nofollow noopener noreferrer">https://your-domain.atlassian.net/rest/api/3/search/jql</a>"
headers = { "Accept": "application/json" }
auth = HTTPBasicAuth("email@example.com", "<api_token>")
query = {
'jql': 'labels is not EMPTY',
'maxResults': 100, 'fields': '[key, labels]'
}
response = requests.request( "GET", url, headers=headers, params=query, auth=auth )
and then loop based on nextPageToken
nextPageToken
It looks like you're new here. Sign in or register to get started.