---
title: Get a token validation rule
---

[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**

# Get a token validation rule

client.TokenValidation.Rules.Get(ctx, ruleID, query) (\*[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)

GET/zones/{zone\_id}/token\_validation/rules/{rule\_id}

Returns a token validation rule by ID.

##### 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``Account API Gateway Read``Domain API Gateway``Domain API Gateway Read`

##### ParametersExpand Collapse

ruleID string

UUID.

maxLength36

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

<details>

<summary>

query RuleGetParams

</summary>

ZoneID param.Field\[string]

Identifier.

maxLength32

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

</details>

[Link to this property](<#(resource)%20token_validation.rules%20%3E%20(method)%20get%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)>)

### Get a token validation rule

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"),
  )
  tokenValidationRule, err := client.TokenValidation.Rules.Get(
    context.TODO(),
    "4a7ee8d3-dd63-4ceb-9d5f-c27831854ce7",
    token_validation.RuleGetParams{
      ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", tokenValidationRule.ID)
}
```

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

##### 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
}
```