Skip to main content

rules

Creates, updates, deletes, gets or lists a rules resource.

Overview

Namerules
TypeResource
Idcloudflare.token_validation.rules

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
idstringUUID. (example: f174e90a-fafe-4643-bbbc-4a0ed4fc8415)
actionstringAction to take on requests that match operations included in selector and fail expression. (log, block) (example: log)
created_atstring (date-time) (example: 2014-01-01T05:20:00.12345Z)
descriptionstringA human-readable description that gives more details than title. (example: Long description for Token Validation Rule)
enabledbooleanToggle rule on or off.
expressionstringRule expression. Requests that fail to match this expression will be subject to action. For details on expressions, see the Cloudflare Docs. (example: is_jwt_valid("52973293-cb04-4a97-8f55-e7d2ad1107dd") or is_jwt_valid("46eab8d1-6376-45e3-968f-2c649d77d423"))
last_updatedstring (date-time) (example: 2014-01-01T05:20:00.12345Z)
selectorobjectSelect operations covered by this rule. For details on selectors, see the Cloudflare Docs.
titlestringA human-readable name for the rule. (example: Example Token Validation Rule)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectzone_id, rule_idGet a zone token validation rule.
listselectzone_idper_page, page, token_configuration, action, enabled, id, rule_id, host, hostnameList token validation rules
createinsertzone_idCreate a token validation rule.
editupdatezone_id, rule_idEdit a zone token validation rule.
deletedeletezone_id, rule_idDelete a zone token validation rule.
previewexeczone_idper_page, page, state, host, hostname, method, endpointPreview operations covered by a Token Validation rule. The API will return all operations on a zone annotated with an additional state field. Operations with an included state will be covered by a Token Validation Rule.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
rule_idstringThe rule ID.
zone_idstringThe Cloudflare zone ID.
actionstring
enabledboolean
endpointarrayFilter operations by endpoint. Allows substring matching.
hostarrayFilter operations by host.
hostnamearrayFilter operations by host.
idstringSelect rules with these IDs.
methodarrayFilter operations by method.
pageintegerPage number of paginated results.
per_pageintegerMaximum number of results per page.
rule_idstringSelect rules with these IDs.
statearray
token_configurationarraySelect rules using any of these token configurations.

SELECT examples

Get a zone token validation rule.

SELECT
id,
action,
created_at,
description,
enabled,
expression,
last_updated,
selector,
title
FROM cloudflare.token_validation.rules
WHERE zone_id = '{{ zone_id }}' -- required
AND rule_id = '{{ rule_id }}' -- required
;

INSERT examples

Create a token validation rule.

INSERT INTO cloudflare.token_validation.rules (
action,
description,
enabled,
expression,
selector,
title,
zone_id
)
SELECT
'{{ action }}',
'{{ description }}',
{{ enabled }},
'{{ expression }}',
'{{ selector }}',
'{{ title }}',
'{{ zone_id }}'
RETURNING
errors,
messages,
result,
success
;

UPDATE examples

Edit a zone token validation rule.

UPDATE cloudflare.token_validation.rules
SET
action = '{{ action }}',
description = '{{ description }}',
enabled = {{ enabled }},
expression = '{{ expression }}',
selector = '{{ selector }}',
title = '{{ title }}',
position = '{{ position }}'
WHERE
zone_id = '{{ zone_id }}' --required
AND rule_id = '{{ rule_id }}' --required
RETURNING
errors,
messages,
result,
success;

DELETE examples

Delete a zone token validation rule.

DELETE FROM cloudflare.token_validation.rules
WHERE zone_id = '{{ zone_id }}' --required
AND rule_id = '{{ rule_id }}' --required
;

Lifecycle Methods

Preview operations covered by a Token Validation rule. The API will return all operations on a zone annotated with an additional state field. Operations with an included state will be covered by a Token Validation Rule.

EXEC cloudflare.token_validation.rules.preview
@zone_id='{{ zone_id }}' --required,
@per_page='{{ per_page }}',
@page='{{ page }}',
@state='{{ state }}',
@host='{{ host }}',
@hostname='{{ hostname }}',
@method='{{ method }}',
@endpoint='{{ endpoint }}'
@@json=
'{
"exclude": "{{ exclude }}",
"include": "{{ include }}"
}'
;