Skip to content
Start here

List token validation rules

token_validation.rules.list(RuleListParams**kwargs) -> SyncV4PagePaginationArray[TokenValidationRule]
GET/zones/{zone_id}/token_validation/rules

List token validation rules

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)
Account API GatewayAccount API Gateway ReadDomain API GatewayDomain API Gateway Read
ParametersExpand Collapse
zone_id: str

Identifier.

maxLength32
id: Optional[str]

Select rules with these IDs.

maxLength36
minLength36
action: Optional[Literal["log", "block"]]

Action to take on requests that match operations included in selector and fail expression.

One of the following:
"log"
"block"
enabled: Optional[bool]

Toggle rule on or off.

host: Optional[str]

Select rules with this host in include.

formathostname
maxLength255
hostname: Optional[str]

Select rules with this host in include.

formathostname
maxLength255
page: Optional[int]

Page number of paginated results.

minimum1
per_page: Optional[int]

Maximum number of results per page.

maximum50
minimum5
rule_id: Optional[str]

Select rules with these IDs.

maxLength36
minLength36
token_configuration: Optional[SequenceNotStr[str]]

Select rules using any of these token configurations.

ReturnsExpand Collapse
class TokenValidationRule:

A Token Validation rule that can enforce security policies using JWT Tokens.

action: Literal["log", "block"]

Action to take on requests that match operations included in selector and fail expression.

One of the following:
"log"
"block"
description: str

A human-readable description that gives more details than title.

maxLength500
enabled: bool

Toggle rule on or off.

expression: str

Rule expression. Requests that fail to match this expression will be subject to action.

For details on expressions, see the Cloudflare Docs.

selector: Selector

Select operations covered by this rule.

For details on selectors, see the Cloudflare Docs.

exclude: Optional[List[SelectorExclude]]

Ignore operations that were otherwise included by include.

operation_ids: Optional[List[str]]

Excluded operation IDs.

include: Optional[List[SelectorInclude]]

Select all matching operations.

host: Optional[List[str]]

Included hostnames.

title: str

A human-readable name for the rule.

maxLength50
id: Optional[str]

UUID.

maxLength36
minLength36
created_at: Optional[datetime]
formatdate-time
last_updated: Optional[datetime]
formatdate-time

List token validation rules

import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
page = client.token_validation.rules.list(
    zone_id="023e105f4ecef8ad9ca31a8372d0c353",
)
page = page.result[0]
print(page.id)
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": [
    {
      "action": "log",
      "description": "Long description for Token Validation Rule",
      "enabled": true,
      "expression": "is_jwt_valid(\"52973293-cb04-4a97-8f55-e7d2ad1107dd\") or is_jwt_valid(\"46eab8d1-6376-45e3-968f-2c649d77d423\")",
      "selector": {
        "exclude": [
          {
            "operation_ids": [
              "f9c5615e-fe15-48ce-bec6-cfc1946f1bec",
              "56828eae-035a-4396-ba07-51c66d680a04"
            ]
          }
        ],
        "include": [
          {
            "host": [
              "v1.example.com",
              "v2.example.com"
            ]
          }
        ]
      },
      "title": "Example Token Validation Rule",
      "id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
      "created_at": "2014-01-01T05:20:00.12345Z",
      "last_updated": "2014-01-01T05:20:00.12345Z"
    }
  ],
  "success": true,
  "result_info": {
    "count": 1,
    "page": 1,
    "per_page": 20,
    "total_count": 2000,
    "total_pages": 100
  }
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": [
    {
      "action": "log",
      "description": "Long description for Token Validation Rule",
      "enabled": true,
      "expression": "is_jwt_valid(\"52973293-cb04-4a97-8f55-e7d2ad1107dd\") or is_jwt_valid(\"46eab8d1-6376-45e3-968f-2c649d77d423\")",
      "selector": {
        "exclude": [
          {
            "operation_ids": [
              "f9c5615e-fe15-48ce-bec6-cfc1946f1bec",
              "56828eae-035a-4396-ba07-51c66d680a04"
            ]
          }
        ],
        "include": [
          {
            "host": [
              "v1.example.com",
              "v2.example.com"
            ]
          }
        ]
      },
      "title": "Example Token Validation Rule",
      "id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
      "created_at": "2014-01-01T05:20:00.12345Z",
      "last_updated": "2014-01-01T05:20:00.12345Z"
    }
  ],
  "success": true,
  "result_info": {
    "count": 1,
    "page": 1,
    "per_page": 20,
    "total_count": 2000,
    "total_pages": 100
  }
}