## Create a token validation rule `client.tokenValidation.rules.create(RuleCreateParamsparams, RequestOptionsoptions?): TokenValidationRule` **post** `/zones/{zone_id}/token_validation/rules` Create a token validation rule. ### Parameters - `params: RuleCreateParams` - `zone_id: string` Path param: Identifier. - `action: "log" | "block"` Body param: Action to take on requests that match operations included in `selector` and fail `expression`. - `"log"` - `"block"` - `description: string` Body param: A human-readable description that gives more details than `title`. - `enabled: boolean` Body param: Toggle rule on or off. - `expression: string` Body param: Rule expression. Requests that fail to match this expression will be subject to `action`. For details on expressions, see the [Cloudflare Docs](https://developers.cloudflare.com/api-shield/security/jwt-validation/). - `selector: Selector` Body param: Select operations covered by this rule. For details on selectors, see the [Cloudflare Docs](https://developers.cloudflare.com/api-shield/security/jwt-validation/). - `exclude?: Array | null` Ignore operations that were otherwise included by `include`. - `operation_ids?: Array` Excluded operation IDs. - `include?: Array | null` Select all matching operations. - `host?: Array` Included hostnames. - `title: string` Body param: A human-readable name for the rule. ### Returns - `TokenValidationRule` A Token Validation rule that can enforce security policies using JWT Tokens. - `action: "log" | "block"` Action to take on requests that match operations included in `selector` and fail `expression`. - `"log"` - `"block"` - `description: string` A human-readable description that gives more details than `title`. - `enabled: boolean` Toggle rule on or off. - `expression: string` Rule expression. Requests that fail to match this expression will be subject to `action`. For details on expressions, see the [Cloudflare Docs](https://developers.cloudflare.com/api-shield/security/jwt-validation/). - `selector: Selector` Select operations covered by this rule. For details on selectors, see the [Cloudflare Docs](https://developers.cloudflare.com/api-shield/security/jwt-validation/). - `exclude?: Array | null` Ignore operations that were otherwise included by `include`. - `operation_ids?: Array` Excluded operation IDs. - `include?: Array | null` Select all matching operations. - `host?: Array` Included hostnames. - `title: string` A human-readable name for the rule. - `id?: string` UUID. - `created_at?: string` - `last_updated?: string` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const tokenValidationRule = await client.tokenValidation.rules.create({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353', 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: {}, title: 'Example Token Validation Rule', }); console.log(tokenValidationRule.id); ``` #### Response ```json { "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 } ```