Skip to content
Start here

Create an account or zone ruleset rule

POST/{accounts_or_zones}/{account_or_zone_id}/rulesets/{ruleset_id}/rules

Adds a new rule to an account or zone ruleset. The rule will be added to the end of the existing list of rules in the ruleset by default.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Mass URL Redirects WriteMagic Firewall WriteL4 DDoS Managed Ruleset WriteTransform Rules WriteSelect Configuration WriteAccount WAF WriteAccount Rulesets WriteLogs Write
Path ParametersExpand Collapse
ruleset_id: string

The unique ID of the ruleset.

account_id: optional string

The Account ID to use for this endpoint. Mutually exclusive with the Zone ID.

zone_id: optional string

The Zone ID to use for this endpoint. Mutually exclusive with the Account ID.

Query ParametersExpand Collapse
dry_run: optional boolean

Validates the request without persisting changes when set to true. Responses that normally return 200 return result: null; endpoints that normally return 204 continue to return 204.

Body ParametersJSONExpand Collapse
body: BlockRule { last_updated, version, id, 10 more } or object { last_updated, version, id, 11 more } or CompressResponseRule { last_updated, version, id, 10 more } or 18 more
One of the following:
BlockRule = BlockRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
ChallengeRule object { last_updated, version, id, 11 more }
last_updated: string

The timestamp of when the rule was last modified.

formatdate-time
version: string

The version of the rule.

id: optional string

The unique ID of the rule.

action: optional "challenge"

The action to perform when the rule matches.

action_parameters: optional unknown

The parameters configuring the rule’s action.

categories: optional array of string

The categories of the rule.

description: optional string

An informative description of the rule.

enabled: optional boolean

Whether the rule should be executed.

exposed_credential_check: optional object { password_expression, username_expression }

Configuration for exposed credential checking.

password_expression: string

An expression that selects the password used in the credentials check.

minLength1
username_expression: string

An expression that selects the user ID used in the credentials check.

minLength1
expression: optional string

The expression defining which traffic will match the rule.

minLength1
logging: optional Logging { enabled }

An object configuring the rule’s logging behavior.

enabled: boolean

Whether to generate a log when the rule matches.

position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
ratelimit: optional object { characteristics, period, counting_expression, 5 more }

An object configuring the rule’s rate limit behavior.

characteristics: array of string

Characteristics of the request on which the rate limit counter will be incremented.

period: number

Period in seconds over which the counter is being incremented.

minimum0
counting_expression: optional string

An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.

minLength1
mitigation_timeout: optional number

Period of time in seconds after which the action will be disabled following its first execution.

requests_per_period: optional number

The threshold of requests per period after which the action will be executed for the first time.

minimum1
requests_to_origin: optional boolean

Whether counting is only performed when an origin is reached.

score_per_period: optional number

The score threshold per period for which the action will be executed the first time.

score_response_header_name: optional string

A response header name provided by the origin, which contains the score to increment rate limit counter with.

minLength1
ref: optional string

The reference of the rule (the rule’s ID by default).

minLength1
ResponseCompressionRule = CompressResponseRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
DDoSDynamicRule = DDoSDynamicRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
ExecuteRule = ExecuteRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
ForceConnectionCloseRule = ForceConnectionCloseRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
JavaScriptChallengeRule object { last_updated, version, id, 11 more }
last_updated: string

The timestamp of when the rule was last modified.

formatdate-time
version: string

The version of the rule.

id: optional string

The unique ID of the rule.

action: optional "js_challenge"

The action to perform when the rule matches.

action_parameters: optional unknown

The parameters configuring the rule’s action.

categories: optional array of string

The categories of the rule.

description: optional string

An informative description of the rule.

enabled: optional boolean

Whether the rule should be executed.

exposed_credential_check: optional object { password_expression, username_expression }

Configuration for exposed credential checking.

password_expression: string

An expression that selects the password used in the credentials check.

minLength1
username_expression: string

An expression that selects the user ID used in the credentials check.

minLength1
expression: optional string

The expression defining which traffic will match the rule.

minLength1
logging: optional Logging { enabled }

An object configuring the rule’s logging behavior.

enabled: boolean

Whether to generate a log when the rule matches.

position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
ratelimit: optional object { characteristics, period, counting_expression, 5 more }

An object configuring the rule’s rate limit behavior.

characteristics: array of string

Characteristics of the request on which the rate limit counter will be incremented.

period: number

Period in seconds over which the counter is being incremented.

minimum0
counting_expression: optional string

An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.

minLength1
mitigation_timeout: optional number

Period of time in seconds after which the action will be disabled following its first execution.

requests_per_period: optional number

The threshold of requests per period after which the action will be executed for the first time.

minimum1
requests_to_origin: optional boolean

Whether counting is only performed when an origin is reached.

score_per_period: optional number

The score threshold per period for which the action will be executed the first time.

score_response_header_name: optional string

A response header name provided by the origin, which contains the score to increment rate limit counter with.

minLength1
ref: optional string

The reference of the rule (the rule’s ID by default).

minLength1
LogRule = LogRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
LogCustomFieldRule = LogCustomFieldRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
ManagedChallengeRule = ManagedChallengeRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
RedirectRule = RedirectRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
RewriteRule = RewriteRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
RouteRule = RouteRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
ScoreRule = ScoreRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
ServeErrorRule = ServeErrorRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
SetCacheControlRule object { last_updated, version, id, 11 more }
last_updated: string

The timestamp of when the rule was last modified.

formatdate-time
version: string

The version of the rule.

id: optional string

The unique ID of the rule.

action: optional "set_cache_control"

The action to perform when the rule matches.

action_parameters: optional object { immutable, "max-age", "must-revalidate", 10 more }

The parameters configuring the rule’s action.

immutable: optional object { operation, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration.

One of the following:
SetDirective object { operation, cloudflare_only }

Set the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"max-age": optional object { operation, value, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration that accepts a duration value in seconds.

One of the following:
SetDirective object { operation, value, cloudflare_only }

Set the directive with a duration value in seconds.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
value: number

The duration value in seconds for the directive.

minimum0
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"must-revalidate": optional object { operation, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration.

One of the following:
SetDirective object { operation, cloudflare_only }

Set the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"must-understand": optional object { operation, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration.

One of the following:
SetDirective object { operation, cloudflare_only }

Set the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"no-cache": optional object { operation, cloudflare_only, qualifiers } or object { operation, cloudflare_only }

A cache-control directive configuration that accepts optional qualifiers (header names).

One of the following:
SetDirective object { operation, cloudflare_only, qualifiers }

Set the directive with optional qualifiers.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

qualifiers: optional array of string

Optional list of header names to qualify the directive (e.g., for “private” or “no-cache” directives).

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"no-store": optional object { operation, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration.

One of the following:
SetDirective object { operation, cloudflare_only }

Set the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"no-transform": optional object { operation, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration.

One of the following:
SetDirective object { operation, cloudflare_only }

Set the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

private: optional object { operation, cloudflare_only, qualifiers } or object { operation, cloudflare_only }

A cache-control directive configuration that accepts optional qualifiers (header names).

One of the following:
SetDirective object { operation, cloudflare_only, qualifiers }

Set the directive with optional qualifiers.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

qualifiers: optional array of string

Optional list of header names to qualify the directive (e.g., for “private” or “no-cache” directives).

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"proxy-revalidate": optional object { operation, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration.

One of the following:
SetDirective object { operation, cloudflare_only }

Set the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

public: optional object { operation, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration.

One of the following:
SetDirective object { operation, cloudflare_only }

Set the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"s-maxage": optional object { operation, value, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration that accepts a duration value in seconds.

One of the following:
SetDirective object { operation, value, cloudflare_only }

Set the directive with a duration value in seconds.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
value: number

The duration value in seconds for the directive.

minimum0
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"stale-if-error": optional object { operation, value, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration that accepts a duration value in seconds.

One of the following:
SetDirective object { operation, value, cloudflare_only }

Set the directive with a duration value in seconds.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
value: number

The duration value in seconds for the directive.

minimum0
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"stale-while-revalidate": optional object { operation, value, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration that accepts a duration value in seconds.

One of the following:
SetDirective object { operation, value, cloudflare_only }

Set the directive with a duration value in seconds.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
value: number

The duration value in seconds for the directive.

minimum0
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

categories: optional array of string

The categories of the rule.

description: optional string

An informative description of the rule.

enabled: optional boolean
exposed_credential_check: optional object { password_expression, username_expression }

Configuration for exposed credential checking.

password_expression: string

An expression that selects the password used in the credentials check.

minLength1
username_expression: string

An expression that selects the user ID used in the credentials check.

minLength1
expression: optional string

The expression defining which traffic will match the rule.

minLength1
logging: optional Logging { enabled }

An object configuring the rule’s logging behavior.

enabled: boolean

Whether to generate a log when the rule matches.

position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
ratelimit: optional object { characteristics, period, counting_expression, 5 more }

An object configuring the rule’s rate limit behavior.

characteristics: array of string

Characteristics of the request on which the rate limit counter will be incremented.

period: number

Period in seconds over which the counter is being incremented.

minimum0
counting_expression: optional string

An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.

minLength1
mitigation_timeout: optional number

Period of time in seconds after which the action will be disabled following its first execution.

requests_per_period: optional number

The threshold of requests per period after which the action will be executed for the first time.

minimum1
requests_to_origin: optional boolean

Whether counting is only performed when an origin is reached.

score_per_period: optional number

The score threshold per period for which the action will be executed the first time.

score_response_header_name: optional string

A response header name provided by the origin, which contains the score to increment rate limit counter with.

minLength1
ref: optional string

The reference of the rule (the rule’s ID by default).

minLength1
SetCacheSettingsRule = SetCacheSettingsRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
SetCacheTagsRule object { last_updated, version, id, 11 more }
last_updated: string

The timestamp of when the rule was last modified.

formatdate-time
version: string

The version of the rule.

id: optional string

The unique ID of the rule.

action: optional "set_cache_tags"

The action to perform when the rule matches.

action_parameters: optional object { operation, values } or object { expression, operation } or object { operation, values } or 3 more

The parameters configuring the rule’s action.

One of the following:
AddCacheTagsValues object { operation, values }

Add cache tags using a list of values.

operation: "add" or "remove" or "set"

The operation to perform on the cache tags.

One of the following:
"add"
"remove"
"set"
values: array of string

A list of cache tag values.

AddCacheTagsExpression object { expression, operation }

Add cache tags using an expression.

expression: string

An expression that evaluates to an array of cache tag values.

minLength1
operation: "add" or "remove" or "set"

The operation to perform on the cache tags.

One of the following:
"add"
"remove"
"set"
RemoveCacheTagsValues object { operation, values }

Remove cache tags using a list of values.

operation: "add" or "remove" or "set"

The operation to perform on the cache tags.

One of the following:
"add"
"remove"
"set"
values: array of string

A list of cache tag values.

RemoveCacheTagsExpression object { expression, operation }

Remove cache tags using an expression.

expression: string

An expression that evaluates to an array of cache tag values.

minLength1
operation: "add" or "remove" or "set"

The operation to perform on the cache tags.

One of the following:
"add"
"remove"
"set"
SetCacheTagsValues object { operation, values }

Set cache tags using a list of values.

operation: "add" or "remove" or "set"

The operation to perform on the cache tags.

One of the following:
"add"
"remove"
"set"
values: array of string

A list of cache tag values.

SetCacheTagsExpression object { expression, operation }

Set cache tags using an expression.

expression: string

An expression that evaluates to an array of cache tag values.

minLength1
operation: "add" or "remove" or "set"

The operation to perform on the cache tags.

One of the following:
"add"
"remove"
"set"
categories: optional array of string

The categories of the rule.

description: optional string

An informative description of the rule.

enabled: optional boolean
exposed_credential_check: optional object { password_expression, username_expression }

Configuration for exposed credential checking.

password_expression: string

An expression that selects the password used in the credentials check.

minLength1
username_expression: string

An expression that selects the user ID used in the credentials check.

minLength1
expression: optional string

The expression defining which traffic will match the rule.

minLength1
logging: optional Logging { enabled }

An object configuring the rule’s logging behavior.

enabled: boolean

Whether to generate a log when the rule matches.

position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
ratelimit: optional object { characteristics, period, counting_expression, 5 more }

An object configuring the rule’s rate limit behavior.

characteristics: array of string

Characteristics of the request on which the rate limit counter will be incremented.

period: number

Period in seconds over which the counter is being incremented.

minimum0
counting_expression: optional string

An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.

minLength1
mitigation_timeout: optional number

Period of time in seconds after which the action will be disabled following its first execution.

requests_per_period: optional number

The threshold of requests per period after which the action will be executed for the first time.

minimum1
requests_to_origin: optional boolean

Whether counting is only performed when an origin is reached.

score_per_period: optional number

The score threshold per period for which the action will be executed the first time.

score_response_header_name: optional string

A response header name provided by the origin, which contains the score to increment rate limit counter with.

minLength1
ref: optional string

The reference of the rule (the rule’s ID by default).

minLength1
SetConfigurationRule = SetConfigRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
SkipRule = SkipRule { last_updated, version, id, 10 more }
position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
TransformResponseHTMLRule object { last_updated, version, id, 11 more }
last_updated: string

The timestamp of when the rule was last modified.

formatdate-time
version: string

The version of the rule.

id: optional string

The unique ID of the rule.

action: optional "transform_response_html"

The action to perform when the rule matches.

action_parameters: optional object { link_maze }

The parameters configuring the rule’s action.

categories: optional array of string

The categories of the rule.

description: optional string

An informative description of the rule.

enabled: optional boolean
exposed_credential_check: optional object { password_expression, username_expression }

Configuration for exposed credential checking.

password_expression: string

An expression that selects the password used in the credentials check.

minLength1
username_expression: string

An expression that selects the user ID used in the credentials check.

minLength1
expression: optional string

The expression defining which traffic will match the rule.

minLength1
logging: optional Logging { enabled }

An object configuring the rule’s logging behavior.

enabled: boolean

Whether to generate a log when the rule matches.

position: optional object { before } or object { after } or object { index }

An object configuring where the rule will be placed.

One of the following:
BeforePosition object { before }

An object configuring where the rule will be placed.

before: optional string

The ID of another rule to place the rule before. An empty value causes the rule to be placed at the top.

AfterPosition object { after }

An object configuring where the rule will be placed.

after: optional string

The ID of another rule to place the rule after. An empty value causes the rule to be placed at the bottom.

IndexPosition object { index }

An object configuring where the rule will be placed.

index: optional number

An index at which to place the rule, where index 1 is the first rule.

minimum1
ratelimit: optional object { characteristics, period, counting_expression, 5 more }

An object configuring the rule’s rate limit behavior.

characteristics: array of string

Characteristics of the request on which the rate limit counter will be incremented.

period: number

Period in seconds over which the counter is being incremented.

minimum0
counting_expression: optional string

An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.

minLength1
mitigation_timeout: optional number

Period of time in seconds after which the action will be disabled following its first execution.

requests_per_period: optional number

The threshold of requests per period after which the action will be executed for the first time.

minimum1
requests_to_origin: optional boolean

Whether counting is only performed when an origin is reached.

score_per_period: optional number

The score threshold per period for which the action will be executed the first time.

score_response_header_name: optional string

A response header name provided by the origin, which contains the score to increment rate limit counter with.

minLength1
ref: optional string

The reference of the rule (the rule’s ID by default).

minLength1
ReturnsExpand Collapse
errors: array of object { message, code, source }

A list of error messages.

message: string

A text description of this message.

minLength1
code: optional number

A unique code for this message.

source: optional object { pointer }

The source of this message.

pointer: string

A JSON pointer to the field that is the source of the message.

minLength1
messages: array of object { message, code, source }

A list of warning messages.

message: string

A text description of this message.

minLength1
code: optional number

A unique code for this message.

source: optional object { pointer }

The source of this message.

pointer: string

A JSON pointer to the field that is the source of the message.

minLength1
result: object { id, kind, last_updated, 5 more } or unknown

A result.

One of the following:
Ruleset object { id, kind, last_updated, 5 more }

A ruleset object.

id: string

The unique ID of the ruleset.

kind: Kind

The kind of the ruleset.

One of the following:
"managed"
"custom"
"root"
"zone"
last_updated: string

The timestamp of when the ruleset was last modified.

formatdate-time
name: string

The human-readable name of the ruleset.

minLength1
phase: Phase

The phase of the ruleset.

One of the following:
"ddos_l4"
"ddos_l7"
"http_config_settings"
"http_custom_errors"
"http_log_custom_fields"
"http_ratelimit"
"http_request_cache_settings"
"http_request_dynamic_redirect"
"http_request_firewall_custom"
"http_request_firewall_managed"
"http_request_late_transform"
"http_request_origin"
"http_request_redirect"
"http_request_sanitize"
"http_request_sbfm"
"http_request_transform"
"http_response_cache_settings"
"http_response_compression"
"http_response_firewall_managed"
"http_response_headers_transform"
"magic_transit"
"magic_transit_ids_managed"
"magic_transit_managed"
"magic_transit_ratelimit"
rules: array of BlockRule { last_updated, version, id, 10 more } or object { id, action, enabled, 10 more } or CompressResponseRule { last_updated, version, id, 10 more } or 18 more

The list of rules in the ruleset.

One of the following:
BlockRule = BlockRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
ChallengeRule object { id, action, enabled, 10 more }
id: string

The unique ID of the rule.

action: "challenge"

The action to perform when the rule matches.

enabled: boolean

Whether the rule should be executed.

expression: string

The expression defining which traffic will match the rule.

minLength1
last_updated: string

The timestamp of when the rule was last modified.

formatdate-time
ref: string

The reference of the rule (the rule’s ID by default).

minLength1
version: string

The version of the rule.

action_parameters: optional unknown

The parameters configuring the rule’s action.

categories: optional array of string

The categories of the rule.

description: optional string

An informative description of the rule.

exposed_credential_check: optional object { password_expression, username_expression }

Configuration for exposed credential checking.

password_expression: string

An expression that selects the password used in the credentials check.

minLength1
username_expression: string

An expression that selects the user ID used in the credentials check.

minLength1
logging: optional Logging { enabled }

An object configuring the rule’s logging behavior.

enabled: boolean

Whether to generate a log when the rule matches.

ratelimit: optional object { characteristics, period, counting_expression, 5 more }

An object configuring the rule’s rate limit behavior.

characteristics: array of string

Characteristics of the request on which the rate limit counter will be incremented.

period: number

Period in seconds over which the counter is being incremented.

minimum0
counting_expression: optional string

An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.

minLength1
mitigation_timeout: optional number

Period of time in seconds after which the action will be disabled following its first execution.

requests_per_period: optional number

The threshold of requests per period after which the action will be executed for the first time.

minimum1
requests_to_origin: optional boolean

Whether counting is only performed when an origin is reached.

score_per_period: optional number

The score threshold per period for which the action will be executed the first time.

score_response_header_name: optional string

A response header name provided by the origin, which contains the score to increment rate limit counter with.

minLength1
ResponseCompressionRule = CompressResponseRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
DDoSDynamicRule = DDoSDynamicRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
ExecuteRule = ExecuteRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
ForceConnectionCloseRule = ForceConnectionCloseRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
JavaScriptChallengeRule object { id, action, enabled, 10 more }
id: string

The unique ID of the rule.

action: "js_challenge"

The action to perform when the rule matches.

enabled: boolean

Whether the rule should be executed.

expression: string

The expression defining which traffic will match the rule.

minLength1
last_updated: string

The timestamp of when the rule was last modified.

formatdate-time
ref: string

The reference of the rule (the rule’s ID by default).

minLength1
version: string

The version of the rule.

action_parameters: optional unknown

The parameters configuring the rule’s action.

categories: optional array of string

The categories of the rule.

description: optional string

An informative description of the rule.

exposed_credential_check: optional object { password_expression, username_expression }

Configuration for exposed credential checking.

password_expression: string

An expression that selects the password used in the credentials check.

minLength1
username_expression: string

An expression that selects the user ID used in the credentials check.

minLength1
logging: optional Logging { enabled }

An object configuring the rule’s logging behavior.

enabled: boolean

Whether to generate a log when the rule matches.

ratelimit: optional object { characteristics, period, counting_expression, 5 more }

An object configuring the rule’s rate limit behavior.

characteristics: array of string

Characteristics of the request on which the rate limit counter will be incremented.

period: number

Period in seconds over which the counter is being incremented.

minimum0
counting_expression: optional string

An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.

minLength1
mitigation_timeout: optional number

Period of time in seconds after which the action will be disabled following its first execution.

requests_per_period: optional number

The threshold of requests per period after which the action will be executed for the first time.

minimum1
requests_to_origin: optional boolean

Whether counting is only performed when an origin is reached.

score_per_period: optional number

The score threshold per period for which the action will be executed the first time.

score_response_header_name: optional string

A response header name provided by the origin, which contains the score to increment rate limit counter with.

minLength1
LogRule = LogRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
LogCustomFieldRule = LogCustomFieldRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
ManagedChallengeRule = ManagedChallengeRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
RedirectRule = RedirectRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
RewriteRule = RewriteRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
RouteRule = RouteRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
ScoreRule = ScoreRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
ServeErrorRule = ServeErrorRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
SetCacheControlRule object { id, action, enabled, 10 more }
id: string

The unique ID of the rule.

action: "set_cache_control"

The action to perform when the rule matches.

enabled: boolean
expression: string

The expression defining which traffic will match the rule.

minLength1
last_updated: string

The timestamp of when the rule was last modified.

formatdate-time
ref: string

The reference of the rule (the rule’s ID by default).

minLength1
version: string

The version of the rule.

action_parameters: optional object { immutable, "max-age", "must-revalidate", 10 more }

The parameters configuring the rule’s action.

immutable: optional object { operation, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration.

One of the following:
SetDirective object { operation, cloudflare_only }

Set the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"max-age": optional object { operation, value, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration that accepts a duration value in seconds.

One of the following:
SetDirective object { operation, value, cloudflare_only }

Set the directive with a duration value in seconds.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
value: number

The duration value in seconds for the directive.

minimum0
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"must-revalidate": optional object { operation, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration.

One of the following:
SetDirective object { operation, cloudflare_only }

Set the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"must-understand": optional object { operation, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration.

One of the following:
SetDirective object { operation, cloudflare_only }

Set the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"no-cache": optional object { operation, cloudflare_only, qualifiers } or object { operation, cloudflare_only }

A cache-control directive configuration that accepts optional qualifiers (header names).

One of the following:
SetDirective object { operation, cloudflare_only, qualifiers }

Set the directive with optional qualifiers.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

qualifiers: optional array of string

Optional list of header names to qualify the directive (e.g., for “private” or “no-cache” directives).

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"no-store": optional object { operation, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration.

One of the following:
SetDirective object { operation, cloudflare_only }

Set the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"no-transform": optional object { operation, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration.

One of the following:
SetDirective object { operation, cloudflare_only }

Set the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

private: optional object { operation, cloudflare_only, qualifiers } or object { operation, cloudflare_only }

A cache-control directive configuration that accepts optional qualifiers (header names).

One of the following:
SetDirective object { operation, cloudflare_only, qualifiers }

Set the directive with optional qualifiers.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

qualifiers: optional array of string

Optional list of header names to qualify the directive (e.g., for “private” or “no-cache” directives).

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"proxy-revalidate": optional object { operation, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration.

One of the following:
SetDirective object { operation, cloudflare_only }

Set the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

public: optional object { operation, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration.

One of the following:
SetDirective object { operation, cloudflare_only }

Set the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"s-maxage": optional object { operation, value, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration that accepts a duration value in seconds.

One of the following:
SetDirective object { operation, value, cloudflare_only }

Set the directive with a duration value in seconds.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
value: number

The duration value in seconds for the directive.

minimum0
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"stale-if-error": optional object { operation, value, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration that accepts a duration value in seconds.

One of the following:
SetDirective object { operation, value, cloudflare_only }

Set the directive with a duration value in seconds.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
value: number

The duration value in seconds for the directive.

minimum0
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

"stale-while-revalidate": optional object { operation, value, cloudflare_only } or object { operation, cloudflare_only }

A cache-control directive configuration that accepts a duration value in seconds.

One of the following:
SetDirective object { operation, value, cloudflare_only }

Set the directive with a duration value in seconds.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
value: number

The duration value in seconds for the directive.

minimum0
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

RemoveDirective object { operation, cloudflare_only }

Remove the directive.

operation: "set" or "remove"

The operation to perform on the cache-control directive.

One of the following:
"set"
"remove"
cloudflare_only: optional boolean

Whether the directive should only be applied to the Cloudflare CDN cache.

categories: optional array of string

The categories of the rule.

description: optional string

An informative description of the rule.

exposed_credential_check: optional object { password_expression, username_expression }

Configuration for exposed credential checking.

password_expression: string

An expression that selects the password used in the credentials check.

minLength1
username_expression: string

An expression that selects the user ID used in the credentials check.

minLength1
logging: optional Logging { enabled }

An object configuring the rule’s logging behavior.

enabled: boolean

Whether to generate a log when the rule matches.

ratelimit: optional object { characteristics, period, counting_expression, 5 more }

An object configuring the rule’s rate limit behavior.

characteristics: array of string

Characteristics of the request on which the rate limit counter will be incremented.

period: number

Period in seconds over which the counter is being incremented.

minimum0
counting_expression: optional string

An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.

minLength1
mitigation_timeout: optional number

Period of time in seconds after which the action will be disabled following its first execution.

requests_per_period: optional number

The threshold of requests per period after which the action will be executed for the first time.

minimum1
requests_to_origin: optional boolean

Whether counting is only performed when an origin is reached.

score_per_period: optional number

The score threshold per period for which the action will be executed the first time.

score_response_header_name: optional string

A response header name provided by the origin, which contains the score to increment rate limit counter with.

minLength1
SetCacheSettingsRule = SetCacheSettingsRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
SetCacheTagsRule object { id, action, enabled, 10 more }
id: string

The unique ID of the rule.

action: "set_cache_tags"

The action to perform when the rule matches.

enabled: boolean
expression: string

The expression defining which traffic will match the rule.

minLength1
last_updated: string

The timestamp of when the rule was last modified.

formatdate-time
ref: string

The reference of the rule (the rule’s ID by default).

minLength1
version: string

The version of the rule.

action_parameters: optional object { operation, values } or object { expression, operation } or object { operation, values } or 3 more

The parameters configuring the rule’s action.

One of the following:
AddCacheTagsValues object { operation, values }

Add cache tags using a list of values.

operation: "add" or "remove" or "set"

The operation to perform on the cache tags.

One of the following:
"add"
"remove"
"set"
values: array of string

A list of cache tag values.

AddCacheTagsExpression object { expression, operation }

Add cache tags using an expression.

expression: string

An expression that evaluates to an array of cache tag values.

minLength1
operation: "add" or "remove" or "set"

The operation to perform on the cache tags.

One of the following:
"add"
"remove"
"set"
RemoveCacheTagsValues object { operation, values }

Remove cache tags using a list of values.

operation: "add" or "remove" or "set"

The operation to perform on the cache tags.

One of the following:
"add"
"remove"
"set"
values: array of string

A list of cache tag values.

RemoveCacheTagsExpression object { expression, operation }

Remove cache tags using an expression.

expression: string

An expression that evaluates to an array of cache tag values.

minLength1
operation: "add" or "remove" or "set"

The operation to perform on the cache tags.

One of the following:
"add"
"remove"
"set"
SetCacheTagsValues object { operation, values }

Set cache tags using a list of values.

operation: "add" or "remove" or "set"

The operation to perform on the cache tags.

One of the following:
"add"
"remove"
"set"
values: array of string

A list of cache tag values.

SetCacheTagsExpression object { expression, operation }

Set cache tags using an expression.

expression: string

An expression that evaluates to an array of cache tag values.

minLength1
operation: "add" or "remove" or "set"

The operation to perform on the cache tags.

One of the following:
"add"
"remove"
"set"
categories: optional array of string

The categories of the rule.

description: optional string

An informative description of the rule.

exposed_credential_check: optional object { password_expression, username_expression }

Configuration for exposed credential checking.

password_expression: string

An expression that selects the password used in the credentials check.

minLength1
username_expression: string

An expression that selects the user ID used in the credentials check.

minLength1
logging: optional Logging { enabled }

An object configuring the rule’s logging behavior.

enabled: boolean

Whether to generate a log when the rule matches.

ratelimit: optional object { characteristics, period, counting_expression, 5 more }

An object configuring the rule’s rate limit behavior.

characteristics: array of string

Characteristics of the request on which the rate limit counter will be incremented.

period: number

Period in seconds over which the counter is being incremented.

minimum0
counting_expression: optional string

An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.

minLength1
mitigation_timeout: optional number

Period of time in seconds after which the action will be disabled following its first execution.

requests_per_period: optional number

The threshold of requests per period after which the action will be executed for the first time.

minimum1
requests_to_origin: optional boolean

Whether counting is only performed when an origin is reached.

score_per_period: optional number

The score threshold per period for which the action will be executed the first time.

score_response_header_name: optional string

A response header name provided by the origin, which contains the score to increment rate limit counter with.

minLength1
SetConfigurationRule = SetConfigRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
SkipRule = SkipRule { last_updated, version, id, 10 more }
id: string
action: string
enabled: boolean
expression: string
ref: string
TransformResponseHTMLRule object { id, action, enabled, 10 more }
id: string

The unique ID of the rule.

action: "transform_response_html"

The action to perform when the rule matches.

enabled: boolean
expression: string

The expression defining which traffic will match the rule.

minLength1
last_updated: string

The timestamp of when the rule was last modified.

formatdate-time
ref: string

The reference of the rule (the rule’s ID by default).

minLength1
version: string

The version of the rule.

action_parameters: optional object { link_maze }

The parameters configuring the rule’s action.

categories: optional array of string

The categories of the rule.

description: optional string

An informative description of the rule.

exposed_credential_check: optional object { password_expression, username_expression }

Configuration for exposed credential checking.

password_expression: string

An expression that selects the password used in the credentials check.

minLength1
username_expression: string

An expression that selects the user ID used in the credentials check.

minLength1
logging: optional Logging { enabled }

An object configuring the rule’s logging behavior.

enabled: boolean

Whether to generate a log when the rule matches.

ratelimit: optional object { characteristics, period, counting_expression, 5 more }

An object configuring the rule’s rate limit behavior.

characteristics: array of string

Characteristics of the request on which the rate limit counter will be incremented.

period: number

Period in seconds over which the counter is being incremented.

minimum0
counting_expression: optional string

An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.

minLength1
mitigation_timeout: optional number

Period of time in seconds after which the action will be disabled following its first execution.

requests_per_period: optional number

The threshold of requests per period after which the action will be executed for the first time.

minimum1
requests_to_origin: optional boolean

Whether counting is only performed when an origin is reached.

score_per_period: optional number

The score threshold per period for which the action will be executed the first time.

score_response_header_name: optional string

A response header name provided by the origin, which contains the score to increment rate limit counter with.

minLength1
version: string

The version of the ruleset.

description: optional string

An informative description of the ruleset.

unknown

Returned when dry_run is true.

success: true

Whether the API call was successful.

Create an account or zone ruleset rule

curl https://api.cloudflare.com/client/v4/$ACCOUNTS_OR_ZONES/$ACCOUNT_OR_ZONE_ID/rulesets/$RULESET_ID/rules \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
    -d '{
          "id": "3a03d665bac047339bb530ecb439a90d",
          "description": "Block the request.",
          "enabled": true,
          "expression": "ip.src eq 1.1.1.1",
          "ref": "my_ref"
        }'
{
  "errors": [
    {
      "message": "something bad happened",
      "code": 10000,
      "source": {
        "pointer": "/rules/0/action"
      }
    }
  ],
  "messages": [
    {
      "message": "something bad happened",
      "code": 10000,
      "source": {
        "pointer": "/rules/0/action"
      }
    }
  ],
  "result": {
    "id": "2f2feab2026849078ba485f918791bdc",
    "kind": "root",
    "last_updated": "2000-01-01T00:00:00Z",
    "name": "My ruleset",
    "phase": "http_request_firewall_custom",
    "rules": [
      {
        "last_updated": "2000-01-01T00:00:00Z",
        "version": "1",
        "id": "id",
        "action": "action",
        "action_parameters": {
          "response": {
            "content": "{\n  \"success\": false,\n  \"error\": \"you have been blocked\"\n}",
            "content_type": "application/json",
            "status_code": 400
          }
        },
        "categories": [
          "directory-traversal"
        ],
        "description": "Block the request.",
        "enabled": true,
        "exposed_credential_check": {
          "password_expression": "url_decode(http.request.body.form[\\\"password\\\"][0])",
          "username_expression": "url_decode(http.request.body.form[\\\"username\\\"][0])"
        },
        "expression": "expression",
        "logging": {
          "enabled": true
        },
        "ratelimit": {
          "characteristics": [
            "cf.colo.id"
          ],
          "period": 60,
          "counting_expression": "http.request.body.raw eq \"abcd\"",
          "mitigation_timeout": 600,
          "requests_per_period": 1000,
          "requests_to_origin": true,
          "score_per_period": 400,
          "score_response_header_name": "my-score"
        },
        "ref": "ref"
      }
    ],
    "version": "1",
    "description": "A description for my ruleset."
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "message": "something bad happened",
      "code": 10000,
      "source": {
        "pointer": "/rules/0/action"
      }
    }
  ],
  "messages": [
    {
      "message": "something bad happened",
      "code": 10000,
      "source": {
        "pointer": "/rules/0/action"
      }
    }
  ],
  "result": {
    "id": "2f2feab2026849078ba485f918791bdc",
    "kind": "root",
    "last_updated": "2000-01-01T00:00:00Z",
    "name": "My ruleset",
    "phase": "http_request_firewall_custom",
    "rules": [
      {
        "last_updated": "2000-01-01T00:00:00Z",
        "version": "1",
        "id": "id",
        "action": "action",
        "action_parameters": {
          "response": {
            "content": "{\n  \"success\": false,\n  \"error\": \"you have been blocked\"\n}",
            "content_type": "application/json",
            "status_code": 400
          }
        },
        "categories": [
          "directory-traversal"
        ],
        "description": "Block the request.",
        "enabled": true,
        "exposed_credential_check": {
          "password_expression": "url_decode(http.request.body.form[\\\"password\\\"][0])",
          "username_expression": "url_decode(http.request.body.form[\\\"username\\\"][0])"
        },
        "expression": "expression",
        "logging": {
          "enabled": true
        },
        "ratelimit": {
          "characteristics": [
            "cf.colo.id"
          ],
          "period": 60,
          "counting_expression": "http.request.body.raw eq \"abcd\"",
          "mitigation_timeout": 600,
          "requests_per_period": 1000,
          "requests_to_origin": true,
          "score_per_period": 400,
          "score_response_header_name": "my-score"
        },
        "ref": "ref"
      }
    ],
    "version": "1",
    "description": "A description for my ruleset."
  },
  "success": true
}