Not working python script with cloudflare api :(((

I want to make script that will turn on my WAF rule, and it is not working, I’ll get response “success” : “true”, but rule is still OFF on my dashboard :frowning:

import requests
import json

# Cloudflare API credentials
API_EMAIL = 'email'
API_KEY = 'key'

# Zone ID and WAF Rule ID
ZONE_ID = 'id'
RULE_ID = 'id'

# API endpoint
API_URL = f'{ZONE_ID}/firewall/rules/{RULE_ID}'

# Headers
headers = {
    'X-Auth-Email': API_EMAIL,
    'X-Auth-Key': API_KEY,
    'Content-Type': 'application/json'

# Payload to enable the WAF rule
data = {
       'enabled' : 'true'

# Send the request to enable the WAF rule
response = requests.patch(API_URL, headers=headers, data=json.dumps(data))

# Check the response status

I can’t find in CF documentation payload to turn off WAF rule, and idea how to do it?

Hi, thanks for your question.

I wonder if this could be related to the move to Custom Rules:

Although the Firewall Rules API should be functioning fine, it may be using different IDs? Which system did you get that rule ID from? And can you try using the Custom Rules API instead?

I was asking about payload for API to turn off rule, I have everything else, and I have already studied documentation again, and I wasn’t able to see any information on how to do it, but there is possibility to change rule, so I’m chaining it in such a way that rule is still on, but it will not work in way I want, so it is for me OFF, but rule is still ON. I would be happy, if soon Cloudflare team consider adding more payloads for api WAF :slight_smile: