---
title: Create token validation rules
---

[Skip to content](#_top)

[API Reference](https://developers.cloudflare.com/api/go)

[Token Validation](https://developers.cloudflare.com/api/go/resources/token_validation)

[Rules](https://developers.cloudflare.com/api/go/resources/token_validation/subresources/rules)

Copy Markdown

Open in **Claude**Open in **ChatGPT**Open in **Cursor**

---

**Copy Markdown****View as Markdown**

# Create token validation rules

client.TokenValidation.Rules.BulkNew(ctx, params) (\*SinglePage\[[TokenValidationRule](<https://developers.cloudflare.com/api/go/resources/token_validation#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)>)], error)

POST/zones/{zone\_id}/token\_validation/rules/bulk

Creates multiple token validation rules for the zone in one request.

##### Security

<details>

<summary>API Token</summary>



The preferred authorization scheme for interacting with the Cloudflare API. <a href="https://developers.cloudflare.com/fundamentals/api/get-started/create-token/">Create a token</a>.

**Example:**<code>Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY</code>

</details>

<details>

<summary>API Email + API Key</summary>



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

**Example:**<code>X-Auth-Email: user@example.com</code>

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

**Example:**<code>X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194</code>

</details>

##### Accepted Permissions (at least one required)

`Account API Gateway``Domain API Gateway`

##### ParametersExpand Collapse

<details>

<summary>

params RuleBulkNewParams

</summary>

ZoneID param.Field\[string]

Path param: Identifier.

maxLength32

<a href="#(resource)%20token_validation.rules%20%3E%20(method)%20bulk_create%20%3E%20(params)%20default%20%3E%20(param)%20zone_id">Link to this property</a>

<details>

<summary>

Body param.Field\[\[]RuleBulkNewParamsBody]

Body param

</summary>

<details>

<summary>

Action RuleBulkNewParamsBodyAction

Action to take on requests that match operations included in <code>selector</code> and fail <code>expression</code>.

</summary>

One of the following:

const RuleBulkNewParamsBodyActionLog RuleBulkNewParamsBodyAction = "log"

<a href="#(resource)%20token_validation.rules%20%3E%20(method)%20bulk_create%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20action%20%3E%20(member)%200">Link to this property</a>

const RuleBulkNewParamsBodyActionBlock RuleBulkNewParamsBodyAction = "block"

<a href="#(resource)%20token_validation.rules%20%3E%20(method)%20bulk_create%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20action%20%3E%20(member)%201">Link to this property</a>

</details>

<a href="#(resource)%20token_validation.rules%20%3E%20(method)%20bulk_create%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20action">Link to this property</a>

Description string

A human-readable description that gives more details than <code>title</code>.

maxLength500

<a href="#(resource)%20token_validation.rules%20%3E%20(method)%20bulk_create%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20description">Link to this property</a>

Enabled bool

Toggle rule on or off.

<a href="#(resource)%20token_validation.rules%20%3E%20(method)%20bulk_create%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20enabled">Link to this property</a>

Expression string

Rule expression. Requests that fail to match this expression will be subject to <code>action</code>.

For details on expressions, see the <a href="https://developers.cloudflare.com/api-shield/security/jwt-validation/">Cloudflare Docs</a>.

<a href="#(resource)%20token_validation.rules%20%3E%20(method)%20bulk_create%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20expression">Link to this property</a>

<details>

<summary>

Selector RuleBulkNewParamsBodySelector

Select operations covered by this rule.

For details on selectors, see the <a href="https://developers.cloudflare.com/api-shield/security/jwt-validation/">Cloudflare Docs</a>.

</summary>

<details>

<summary>

Exclude \[]RuleBulkNewParamsBodySelectorExcludeOptional

Ignore operations that were otherwise included by <code>include</code>.

</summary>

OperationIDs \[]stringOptional

Excluded operation IDs.

<a href="#(resource)%20token_validation.rules%20%3E%20(method)%20bulk_create%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20selector%20%3E%20(property)%20exclude%20%3E%20(items)%20%3E%20(property)%20operation_ids">Link to this property</a>

</details>

<a href="#(resource)%20token_validation.rules%20%3E%20(method)%20bulk_create%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20selector%20%3E%20(property)%20exclude">Link to this property</a>

<details>

<summary>

Include \[]RuleBulkNewParamsBodySelectorIncludeOptional

Select all matching operations.

</summary>

Host \[]stringOptional

Included hostnames.

<a href="#(resource)%20token_validation.rules%20%3E%20(method)%20bulk_create%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20selector%20%3E%20(property)%20include%20%3E%20(items)%20%3E%20(property)%20host">Link to this property</a>

</details>

<a href="#(resource)%20token_validation.rules%20%3E%20(method)%20bulk_create%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20selector%20%3E%20(property)%20include">Link to this property</a>

</details>

<a href="#(resource)%20token_validation.rules%20%3E%20(method)%20bulk_create%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20selector">Link to this property</a>

Title string

A human-readable name for the rule.

maxLength50

<a href="#(resource)%20token_validation.rules%20%3E%20(method)%20bulk_create%20%3E%20(params)%20default%20%3E%20(param)%20body%20%3E%20(schema)%20%3E%20(items)%20%3E%20(property)%20title">Link to this property</a>

</details>

<a href="#(resource)%20token_validation.rules%20%3E%20(method)%20bulk_create%20%3E%20(params)%20default%20%3E%20(param)%20body">Link to this property</a>

</details>

[Link to this property](<#(resource)%20token_validation.rules%20%3E%20(method)%20bulk_create%20%3E%20(params)%20default>)

##### ReturnsExpand Collapse

<details>

<summary>

type TokenValidationRule struct{…}

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

</summary>

<details>

<summary>

Action TokenValidationRuleAction

Action to take on requests that match operations included in <code>selector</code> and fail <code>expression</code>.

</summary>

One of the following:

const TokenValidationRuleActionLog TokenValidationRuleAction = "log"

<a href="#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)%20%3E%20(property)%20action%20%3E%20(member)%200">Link to this property</a>

const TokenValidationRuleActionBlock TokenValidationRuleAction = "block"

<a href="#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)%20%3E%20(property)%20action%20%3E%20(member)%201">Link to this property</a>

</details>

<a href="#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)%20%3E%20(property)%20action">Link to this property</a>

Description string

A human-readable description that gives more details than <code>title</code>.

maxLength500

<a href="#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)%20%3E%20(property)%20description">Link to this property</a>

Enabled bool

Toggle rule on or off.

<a href="#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)%20%3E%20(property)%20enabled">Link to this property</a>

Expression string

Rule expression. Requests that fail to match this expression will be subject to <code>action</code>.

For details on expressions, see the <a href="https://developers.cloudflare.com/api-shield/security/jwt-validation/">Cloudflare Docs</a>.

<a href="#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)%20%3E%20(property)%20expression">Link to this property</a>

<details>

<summary>

Selector TokenValidationRuleSelector

Select operations covered by this rule.

For details on selectors, see the <a href="https://developers.cloudflare.com/api-shield/security/jwt-validation/">Cloudflare Docs</a>.

</summary>

<details>

<summary>

Exclude \[]TokenValidationRuleSelectorExcludeOptional

Ignore operations that were otherwise included by <code>include</code>.

</summary>

OperationIDs \[]stringOptional

Excluded operation IDs.

<a href="#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)%20%3E%20(property)%20selector%20%3E%20(property)%20exclude%20%3E%20(items)%20%3E%20(property)%20operation_ids">Link to this property</a>

</details>

<a href="#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)%20%3E%20(property)%20selector%20%3E%20(property)%20exclude">Link to this property</a>

<details>

<summary>

Include \[]TokenValidationRuleSelectorIncludeOptional

Select all matching operations.

</summary>

Host \[]stringOptional

Included hostnames.

<a href="#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)%20%3E%20(property)%20selector%20%3E%20(property)%20include%20%3E%20(items)%20%3E%20(property)%20host">Link to this property</a>

</details>

<a href="#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)%20%3E%20(property)%20selector%20%3E%20(property)%20include">Link to this property</a>

</details>

<a href="#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)%20%3E%20(property)%20selector">Link to this property</a>

Title string

A human-readable name for the rule.

maxLength50

<a href="#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)%20%3E%20(property)%20title">Link to this property</a>

ID stringOptional

UUID.

maxLength36

minLength36

<a href="#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)%20%3E%20(property)%20id">Link to this property</a>

CreatedAt TimeOptional

formatdate-time

<a href="#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)%20%3E%20(property)%20created_at">Link to this property</a>

LastUpdated TimeOptional

formatdate-time

<a href="#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)%20%3E%20(property)%20last_updated">Link to this property</a>

</details>

[Link to this property](<#(resource)%20token_validation.rules%20%3E%20(model)%20token_validation_rule%20%3E%20(schema)>)

### Create token validation rules

Go

HTTPTypeScriptPythonGoTerraform

```
package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/option"
  "github.com/cloudflare/cloudflare-go/token_validation"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  page, err := client.TokenValidation.Rules.BulkNew(context.TODO(), token_validation.RuleBulkNewParams{
    ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    Body: []token_validation.RuleBulkNewParamsBody{token_validation.RuleBulkNewParamsBody{
      Action: cloudflare.F(token_validation.RuleBulkNewParamsBodyActionLog),
      Description: cloudflare.F("Long description for Token Validation Rule"),
      Enabled: cloudflare.F(true),
      Expression: cloudflare.F(`is_jwt_valid("52973293-cb04-4a97-8f55-e7d2ad1107dd") or is_jwt_valid("46eab8d1-6376-45e3-968f-2c649d77d423")`),
      Selector: cloudflare.F(token_validation.RuleBulkNewParamsBodySelector{

      }),
      Title: cloudflare.F("Example Token Validation Rule"),
    }},
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", page)
}
```

200 example

```
{
  "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

200 example

```
{
  "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
  }
}
```