How to delete IP in blacklist objects through API

nabuhonodozor

Renowned Member
Feb 14, 2010
35
2
73
Hi,
I am building a script solely to manage IP in blacklist objects. So far It authorize correctly, I can download a list of objects and I can add new IP to a list. I am struggling with removing / deleting IP from that blacklist_objects list.

In API docummentation I dont see any DELETE (https://pmg.proxmox.com/pmg-docs/api-viewer/index.html#/config/ruledb/who/{ogroup}/ip)

Please help me how to delete IP from that list.

I am using following code:

Python:
# Function to remove a specific IP from the blacklist
def remove_ip_from_blacklist(ip):
    ticket, csrf_token = get_ticket_and_csrf()
    if ticket and csrf_token:
        headers = {'Cookie': f'PMGAuthCookie={ticket}', 'CSRFPreventionToken': csrf_token}
        delete_ip_url = f'{PMG_API_URL}/config/ruledb/who/2/ip?ip={ip}'
        try:
            response = requests.delete(delete_ip_url, headers=headers, verify=False)
            response.raise_for_status()
            print(f"IP {ip} has been successfully removed from the blacklist.")
        except requests.exceptions.HTTPError as e:
            print(f"Failed to remove IP {ip} from the blacklist: {e}")
    else:
        print("Failed to obtain ticket and CSRF token.")

# Main function
def main():
    # IP to remove from the blacklist
    ip_to_remove = '192.168.1.1'

    # Remove the IP from the blacklist
    remove_ip_from_blacklist(ip_to_remove)

So far I am getting following error:
Failed to remove IP 192.168.1.1 from the blacklist: 501 Server Error: Method 'DELETE /config/ruledb/who/2/ip/192.168.1.1' not implemented for url: https://pmg.mydomain.com:8006/api2/json/config/ruledb/who/2/ip/192.168.1.1
 
Last edited:
  • Like
Reactions: nabuhonodozor