| [ Web Proxy ] |
| Viewing: https://developers.cloudflare.com/ruleset-engine/custom-rulesets/create-custom-ruleset/ | [Back] [Original] |
Use the Create an account or zone ruleset operation to create a custom ruleset, making sure that you:
kind field to custom.phase field.You can also specify the list of rules to include in the custom ruleset in the rules array. To add rules after creating the custom ruleset, refer to Add rules to a custom ruleset.
If you are using Terraform, refer to WAF custom rules configuration using Terraform for examples of creating and deploying custom rulesets.
If you are using the Cloudflare dashboard, refer to Work with custom rulesets in the dashboard.
Note
Currently, zone-level custom rulesets are only available in the http_request_firewall_custom phase.
The following request creates a new custom ruleset at the account level. The response will include the ID of the new custom ruleset in the id field.
Required API token permissions
At least one of the following token permissions is required:Mass URL Redirects WriteMagic Firewall WriteL4 DDoS Managed Ruleset WriteTransform Rules WriteSelect Configuration WriteAccount WAF WriteAccount Rulesets WriteLogs Writecurl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/rulesets" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Custom Ruleset 1",
"description": "My First Custom Ruleset (account)",
"kind": "custom",
"phase": "http_request_firewall_custom"
}'
{
"result": {
"id": "f82ccda3d21f4a02825d3fe45b5e1c10",
"name": "Custom Ruleset 1",
"description": "My First Custom Ruleset (account)",
"kind": "custom",
"version": "1",
"last_updated": "2025-08-09T10:27:30.636197Z",
"phase": "http_request_firewall_custom"
},
"success": true,
"errors": [],
"messages": []
}
You can include a list of rules in the custom ruleset creation request. If you have not added any rules, refer to Add rules to a custom ruleset for more information.
The following request creates a new custom ruleset at the zone level. The response will include the ID of the new custom ruleset in the id field.
Required API token permissions
At least one of the following token permissions is required:Response Compression WriteConfig Settings WriteDynamic URL Redirects WriteCache Settings WriteCustom Errors WriteOrigin WriteManaged headers WriteZone Transform Rules WriteMass URL Redirects WriteMagic Firewall WriteL4 DDoS Managed Ruleset WriteHTTP DDoS Managed Ruleset WriteSanitize WriteTransform Rules WriteSelect Configuration WriteBot Management WriteZone WAF WriteAccount WAF WriteAccount Rulesets WriteLogs WriteLogs Writecurl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Custom Ruleset 1",
"description": "My First Custom Ruleset (zone)",
"kind": "custom",
"phase": "http_request_firewall_custom"
}'
{
"result": {
"id": "f82ccda3d21f4a02825d3fe45b5e1c10",
"name": "Custom Ruleset 1",
"description": "My First Custom Ruleset (zone)",
"kind": "custom",
"version": "1",
"last_updated": "2025-08-09T10:27:30.636197Z",
"phase": "http_request_firewall_custom"
},
"success": true,
"errors": [],
"messages": []
}
You can include a list of rules in the custom ruleset creation request. If you have not added any rules, refer to Add rules to a custom ruleset for more information.
Note
Currently, zone-level custom rulesets are only available in the http_request_firewall_custom phase.
| Web Proxy Viewer | New URL | Original Page |