How to validate all Filters in Jira
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
Several changes in Jira may break previously saved Filters and the Admins may want to validate all existing Filters to pro-actively address them
Changes that may break saved Filters include — but are not limited to — deletions or name changes in:
Issue Statuses
Issue Types
Select Options
Custom Fields
Issue Link Types
Project Names or Keys
In any of the above scenarios, the REST API endpoint for the search will result in an HTTP 400, indicating that the JQL is malformed.
Solution
We'll rely on a DB query to build the list of Filters to query and REST API requests to validate the Filter's JQL syntax.
Overview
Fetch all filters from the DB and save their IDs into a text file (one Id per line)
You can even filter the file out by any criteria you want
Create a temporaryPAT (Personal Access Tokens)in Jira
For each Filter Id:
Get the encoded "searchURL" from the/rest/api/2/filter/IDendpoint
Request the searchURL with additional params like&maxResults=0&fields=id
Print the HTTP code and Filter Id
Fetching all Filters
You can create a filters_ids.txt file from the DB output of:
1
select id from searchrequest;
Or somehow use the wider results to decide which Filter Ids you'll put into the file:
1
select * from searchrequest;
The example Shellscript below reads from a filters_ids.txt like this (no header and only one Id per line):
1
2
3
4
10000
10001
10100
10101
Example Shellscript
This snippet uses curl
, jq
and tee
to accomplish this:
1
2
3
4
5
pat='MTk2ODkwOTYwODAyOuL+ozm2aOKfFAU+Dg79K1TlDFXX'; \
cat filters_ids.txt | while read -r fid; do \
searchUrl="$(curl -H "Authorization: Bearer $pat" -X GET "https://jira-base-URL/rest/api/2/filter/$fid" -s | jq -j '.searchUrl')"; \
curl -H "Authorization: Bearer $pat" -X GET "$searchUrl&maxResults=0&fields=id" -s -o /dev/null -w "%{http_code}\t$fid\n" | tee -a filter_results.txt; \
done
Replace the PAT and //jira-base-URL accordingly to your instance.
This will print the HTTP Response Code and the Filter Id to the terminal and also to the "filter_results.txt" file:
Sample output
1
2
3
4
200 10000
200 10001
400 10100
200 10101
On this example, Filter Id 10100 had a deleted Status in it's clauses, thus return a HTTP 400 when it's JQL was executed.
This may help Admins filter the Filters that had 400 as output and manually browse them to check the failure reason (there may be more than one):
1
https://jira-base-URL/issues/?filter=10100
Where 10100 is the Id of a Filter that failed with 400 in the script, for example.
Was this helpful?