Create an account or zone ruleset rule
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.
Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYYAPI Email + API Key
The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.
X-Auth-Email: user@example.comThe previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.
X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194Accepted Permissions (at least one required)
Mass URL Redirects WriteMagic Firewall WriteL4 DDoS Managed Ruleset WriteTransform Rules WriteSelect Configuration WriteAccount WAF WriteAccount Rulesets WriteLogs WriteParametersExpand Collapse
The Account ID to use for this endpoint. Mutually exclusive with the Zone ID.
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.
An object configuring where the rule will be placed.
An object configuring where the rule will be placed.
An object configuring the rule’s rate limit behavior.
An object configuring the rule’s rate limit behavior.
Characteristics of the request on which the rate limit counter will be incremented.
An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.
Period of time in seconds after which the action will be disabled following its first execution.
The threshold of requests per period after which the action will be executed for the first time.
ReturnsExpand Collapse
A result.
A result.
class Ruleset: …A ruleset object.
A ruleset object.
rules: List[RulesetRule]The list of rules in the ruleset.
The list of rules in the ruleset.
class RulesetRuleChallengeRule: …
exposed_credential_check: Optional[RulesetRuleChallengeRuleExposedCredentialCheck]Configuration for exposed credential checking.
Configuration for exposed credential checking.
ratelimit: Optional[RulesetRuleChallengeRuleRatelimit]An object configuring the rule’s rate limit behavior.
An object configuring the rule’s rate limit behavior.
Characteristics of the request on which the rate limit counter will be incremented.
An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.
Period of time in seconds after which the action will be disabled following its first execution.
The threshold of requests per period after which the action will be executed for the first time.
class RulesetRuleJavaScriptChallengeRule: …
exposed_credential_check: Optional[RulesetRuleJavaScriptChallengeRuleExposedCredentialCheck]Configuration for exposed credential checking.
Configuration for exposed credential checking.
ratelimit: Optional[RulesetRuleJavaScriptChallengeRuleRatelimit]An object configuring the rule’s rate limit behavior.
An object configuring the rule’s rate limit behavior.
Characteristics of the request on which the rate limit counter will be incremented.
An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.
Period of time in seconds after which the action will be disabled following its first execution.
The threshold of requests per period after which the action will be executed for the first time.
class RulesetRuleSetCacheControlRule: …
action_parameters: Optional[RulesetRuleSetCacheControlRuleActionParameters]The parameters configuring the rule’s action.
The parameters configuring the rule’s action.
immutable: Optional[RulesetRuleSetCacheControlRuleActionParametersImmutable]A cache-control directive configuration.
A cache-control directive configuration.
max_age: Optional[RulesetRuleSetCacheControlRuleActionParametersMaxAge]A cache-control directive configuration that accepts a duration value in seconds.
A cache-control directive configuration that accepts a duration value in seconds.
must_revalidate: Optional[RulesetRuleSetCacheControlRuleActionParametersMustRevalidate]A cache-control directive configuration.
A cache-control directive configuration.
must_understand: Optional[RulesetRuleSetCacheControlRuleActionParametersMustUnderstand]A cache-control directive configuration.
A cache-control directive configuration.
no_cache: Optional[RulesetRuleSetCacheControlRuleActionParametersNoCache]A cache-control directive configuration that accepts optional qualifiers (header names).
A cache-control directive configuration that accepts optional qualifiers (header names).
class RulesetRuleSetCacheControlRuleActionParametersNoCacheSetDirective: …Set the directive with optional qualifiers.
Set the directive with optional qualifiers.
no_store: Optional[RulesetRuleSetCacheControlRuleActionParametersNoStore]A cache-control directive configuration.
A cache-control directive configuration.
no_transform: Optional[RulesetRuleSetCacheControlRuleActionParametersNoTransform]A cache-control directive configuration.
A cache-control directive configuration.
private: Optional[RulesetRuleSetCacheControlRuleActionParametersPrivate]A cache-control directive configuration that accepts optional qualifiers (header names).
A cache-control directive configuration that accepts optional qualifiers (header names).
class RulesetRuleSetCacheControlRuleActionParametersPrivateSetDirective: …Set the directive with optional qualifiers.
Set the directive with optional qualifiers.
proxy_revalidate: Optional[RulesetRuleSetCacheControlRuleActionParametersProxyRevalidate]A cache-control directive configuration.
A cache-control directive configuration.
public: Optional[RulesetRuleSetCacheControlRuleActionParametersPublic]A cache-control directive configuration.
A cache-control directive configuration.
s_maxage: Optional[RulesetRuleSetCacheControlRuleActionParametersSMaxage]A cache-control directive configuration that accepts a duration value in seconds.
A cache-control directive configuration that accepts a duration value in seconds.
stale_if_error: Optional[RulesetRuleSetCacheControlRuleActionParametersStaleIfError]A cache-control directive configuration that accepts a duration value in seconds.
A cache-control directive configuration that accepts a duration value in seconds.
stale_while_revalidate: Optional[RulesetRuleSetCacheControlRuleActionParametersStaleWhileRevalidate]A cache-control directive configuration that accepts a duration value in seconds.
A cache-control directive configuration that accepts a duration value in seconds.
exposed_credential_check: Optional[RulesetRuleSetCacheControlRuleExposedCredentialCheck]Configuration for exposed credential checking.
Configuration for exposed credential checking.
ratelimit: Optional[RulesetRuleSetCacheControlRuleRatelimit]An object configuring the rule’s rate limit behavior.
An object configuring the rule’s rate limit behavior.
Characteristics of the request on which the rate limit counter will be incremented.
An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.
Period of time in seconds after which the action will be disabled following its first execution.
The threshold of requests per period after which the action will be executed for the first time.
class RulesetRuleSetCacheTagsRule: …
action_parameters: Optional[RulesetRuleSetCacheTagsRuleActionParameters]The parameters configuring the rule’s action.
The parameters configuring the rule’s action.
class RulesetRuleSetCacheTagsRuleActionParametersAddCacheTagsValues: …Add cache tags using a list of values.
Add cache tags using a list of values.
class RulesetRuleSetCacheTagsRuleActionParametersAddCacheTagsExpression: …Add cache tags using an expression.
Add cache tags using an expression.
class RulesetRuleSetCacheTagsRuleActionParametersRemoveCacheTagsValues: …Remove cache tags using a list of values.
Remove cache tags using a list of values.
class RulesetRuleSetCacheTagsRuleActionParametersRemoveCacheTagsExpression: …Remove cache tags using an expression.
Remove cache tags using an expression.
class RulesetRuleSetCacheTagsRuleActionParametersSetCacheTagsValues: …Set cache tags using a list of values.
Set cache tags using a list of values.
exposed_credential_check: Optional[RulesetRuleSetCacheTagsRuleExposedCredentialCheck]Configuration for exposed credential checking.
Configuration for exposed credential checking.
ratelimit: Optional[RulesetRuleSetCacheTagsRuleRatelimit]An object configuring the rule’s rate limit behavior.
An object configuring the rule’s rate limit behavior.
Characteristics of the request on which the rate limit counter will be incremented.
An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.
Period of time in seconds after which the action will be disabled following its first execution.
The threshold of requests per period after which the action will be executed for the first time.
class RulesetRuleTransformResponseHTMLRule: …
action_parameters: Optional[RulesetRuleTransformResponseHTMLRuleActionParameters]The parameters configuring the rule’s action.
The parameters configuring the rule’s action.
exposed_credential_check: Optional[RulesetRuleTransformResponseHTMLRuleExposedCredentialCheck]Configuration for exposed credential checking.
Configuration for exposed credential checking.
ratelimit: Optional[RulesetRuleTransformResponseHTMLRuleRatelimit]An object configuring the rule’s rate limit behavior.
An object configuring the rule’s rate limit behavior.
Characteristics of the request on which the rate limit counter will be incremented.
An expression that defines when the rate limit counter should be incremented. It defaults to the same as the rule’s expression.
Period of time in seconds after which the action will be disabled following its first execution.
The threshold of requests per period after which the action will be executed for the first time.
Create an account or zone ruleset rule
import os
from cloudflare import Cloudflare
client = Cloudflare(
api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted
)
rule = client.rulesets.rules.create(
ruleset_id="2f2feab2026849078ba485f918791bdc",
account_id="account_id",
)
print(rule){
"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": {},
"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": {},
"success": true
}