Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Can't delete filter via rest api

Maralee Grajo March 27, 2025

Hi I have created a rest api via python script and I have encountered an error due to "the anonymous user is not allowed to create, modify or delete saved filters".  My role is jira admin. The filter is active and I have update the viewers from private to public (vice-versa) but same result. Here is the script that I have used:

 

 

#dummy test for private
import requests
from requests.auth import HTTPBasicAuth
import json

auth = HTTPBasicAuth("<user>", "<api-token>")
jira_url="<url>"
filter_id = 'Test'

# Construct the URL for the DELETE request
delete_url = f'{jira_url}/rest/api/3/filter/{filter_id}'

# Make the DELETE request
response = requests.get(delete_url, auth=auth)

# Check the response status
if response.status_code == 204:
    print(f'Filter {filter_id} deleted successfully.')
else:
    print(f'Failed to delete filter {filter_id}. Status code: {response.status_code}')
    print(response.text)

3 answers

1 vote
Akhand Pratap Singh
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.
March 27, 2025

Hi @Maralee Grajo 

I think you are using .get() in your response, may be try for .delete()

Referhttps://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-filters/#api-rest-api-3-filter-id-delete

Maralee Grajo March 27, 2025

Hi Akhand,

thank you for your respond, I have tried to update the response function to delete but still same result.

 

#dummy test for private
import requests
from requests.auth import HTTPBasicAuth
import json

 

auth = HTTPBasicAuth("<user>""<api-token>")
jira_url="<url>"
filter_id = 'Test'

 

# Construct the URL for the DELETE request
delete_url = f'{jira_url}/rest/api/3/filter/{filter_id}'

 

# Make the DELETE request
response = requests.delete(delete_urlauth=auth)

 

# Check the response status
if response.status_code == 204:
    print(f'Filter {filter_id} deleted successfully.')
else:
    print(f'Failed to delete filter {filter_id}. Status code: {response.status_code}')
    print(response.text)
result: Failed to delete filter Test. Status code: 400
{"errorMessages":["The anonymous user is not allowed to create, modify or delete saved filters."],"errors":{}}
Akhand Pratap Singh
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.
March 27, 2025

@Maralee Grajo 

Can you quickly check below once. 

1. URL passed is something like: url = "https://your-domain.atlassian.net/rest/api/3/filter/{id}"

2. In the auth, you are using Email and API token 

3. If you have administer Jira Global permission or you are the creator of the filter.

 

Status code 400: usually means Bad request and is returned when filter is not found but at the same time error states that anonymous user is not allowed, maybe just recheck once on the above factors.

0 votes
Maralee Grajo March 28, 2025

Hi @Akhand Pratap Singh ,

 

sorry you can forget my last message the script is now working I just need to recreate new api token to execute it.

Akhand Pratap Singh
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.
March 28, 2025

That is amazing, my next suggestion would have been that only.

Glad that it is working.

0 votes
Maralee Grajo March 28, 2025

Hi @Akhand Pratap Singh ,

 

I have check the this 3 items that you have mentioned here is the update script: 

import requests
from requests.auth import HTTPBasicAuth
import json

auth = HTTPBasicAuth("<email>", "<api-token>")
jira_url="https://<companyname>.atlassian.net"
filter_id = '34382'

# Construct the URL for the DELETE request
delete_url = f'{jira_url}/rest/api/3/filter/{filter_id}'

# Make the DELETE request
response = requests.delete(delete_url, auth=auth)

# Check the response status
if response.status_code == 204:
    print(f'Filter {filter_id} deleted successfully.')
else:
    print(f'Failed to delete filter {filter_id}. Status code: {response.status_code}')
    print(response.text)

 I have a site-admin role, and the filter I want to delete is owned by me.

Suggest an answer

Log in or Sign up to answer