How to Find Unused Custom Fields in Jira Cloud Using REST API in Python

Algorithm:

  1. Get all custom fields (CFs), using HTTP GET <server>/rest/api/3/field/search
  2. You need to get the CF's screens and contexts, so the query string would is:  
    'type=custom&orderBy=name&expand=screensCount,contextsCount'
  3. Build a dict of all unused CFs (dict key is ID, since custom field names are not unique)
  4. A CF is considered unused if its screen count == 0 or context count == 0
  5. In the returned JSON for a CF, there are keys 'screenCount' and 'contextCount'. If a key is not present, it means that the count is 0.

Notes:

  1. You'll need to generate an API token to use the REST API
  2. The above REST API endpoint returns paginated data, so you will need to iterate on the results, using the total,  startAt and maxResults, as explained here:
    1. https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#expansion
  3. Note that in most cases, the context count (CC) is 1 and it actually means that it's the 'global' context (meaning that the CF can be used in any project, any issue type).
    1. That does not necessarily mean that the CF is actually used. However, if CC==0, it does mean that the CF is unused.

 

1 comment

Daniel Ebers
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.
May 29, 2022

Hi @Amir Katz (Outseer)
thanks for the great article - we use it meanwhile regularly.

While I totally agree for the part of the contexts...

Note that in most cases, the context count (CC) is 1 and it actually means that it's the 'global' context (meaning that the CF can be used in any project, any issue type).

  1. That does not necessarily mean that the CF is actually used. However, if CC==0, it does mean that the CF is unused.

... we found that having a field not on any screen could be a misleading signal. Sometimes we found admins removed it temporarily from screens but the field is still holding values for at least one issue.
We feel some kind of double checking is something useful to do - in order not to delete any data which would be considered still needed.

Regards,
Daniel

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events