# Precursor ## Get Zone Precursor Config `client.Precursor.Get(ctx, query) (*PrecursorConfig, error)` **get** `/zones/{zone_id}/precursor` Retrieve a zone's Precursor configuration: the zone-level `default_mode` and the ordered list of `enforcement_rules`. ### Parameters - `query PrecursorGetParams` - `ZoneID param.Field[string]` Identifier. ### Returns - `type PrecursorConfig struct{…}` - `DefaultMode PrecursorConfigDefaultMode` The zone-level Precursor enforcement mode applied to requests that do not match a more specific enforcement rule. - `const PrecursorConfigDefaultModeOff PrecursorConfigDefaultMode = "off"` - `const PrecursorConfigDefaultModeMinFriction PrecursorConfigDefaultMode = "min-friction"` - `const PrecursorConfigDefaultModeMaxSecurity PrecursorConfigDefaultMode = "max-security"` - `EnforcementRules []EnforcementRule` The ordered list of enforcement rules for the zone. - `Expression string` The filter expression that determines which requests the rule matches. - `Mode EnforcementRuleMode` The override mode Precursor applies to requests matching an enforcement rule. Unlike `default_mode`, this cannot be `off`. - `const EnforcementRuleModeMinFriction EnforcementRuleMode = "min-friction"` - `const EnforcementRuleModeMaxSecurity EnforcementRuleMode = "max-security"` - `ID string` The read-only identifier that Cloudflare assigns to the rule. - `Description string` An informative description of the rule. - `Enabled bool` Whether the rule is active. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/precursor" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) precursorConfig, err := client.Precursor.Get(context.TODO(), precursor.PrecursorGetParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", precursorConfig.DefaultMode) } ``` #### 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" } } ], "success": true, "result": { "default_mode": "min-friction", "enforcement_rules": [ { "expression": "http.request.uri.path eq \"/shop\"", "mode": "max-security", "id": "3a03d665bac043e3a684e0d385a4b1e2", "description": "Enforce max-security on the shop page", "enabled": true } ] } } ``` ## Update Zone Precursor Config `client.Precursor.Update(ctx, params) (*PrecursorConfig, error)` **put** `/zones/{zone_id}/precursor` Updates the Precursor configuration for a zone. `default_mode` sets the zone-level enforcement mode. `enforcement_rules` is the ordered list of rules that override enforcement for matching requests. This is a partial update: only the fields present in the request body are changed. - Sending an empty array (`[]`) clears all enforcement rules. - At least one of `default_mode` or `enforcement_rules` must be present; an empty body (`{}`) is rejected with `400`. - Rule `id` is read-only (assigned by Cloudflare) and ignored on input. - Rule `mode` must be `min-friction` or `max-security` (`off` is not a valid rule mode; use `default_mode` to disable enforcement). ### Parameters - `params PrecursorUpdateParams` - `ZoneID param.Field[string]` Path param: Identifier. - `PrecursorConfig param.Field[PrecursorConfig]` Body param ### Returns - `type PrecursorConfig struct{…}` - `DefaultMode PrecursorConfigDefaultMode` The zone-level Precursor enforcement mode applied to requests that do not match a more specific enforcement rule. - `const PrecursorConfigDefaultModeOff PrecursorConfigDefaultMode = "off"` - `const PrecursorConfigDefaultModeMinFriction PrecursorConfigDefaultMode = "min-friction"` - `const PrecursorConfigDefaultModeMaxSecurity PrecursorConfigDefaultMode = "max-security"` - `EnforcementRules []EnforcementRule` The ordered list of enforcement rules for the zone. - `Expression string` The filter expression that determines which requests the rule matches. - `Mode EnforcementRuleMode` The override mode Precursor applies to requests matching an enforcement rule. Unlike `default_mode`, this cannot be `off`. - `const EnforcementRuleModeMinFriction EnforcementRuleMode = "min-friction"` - `const EnforcementRuleModeMaxSecurity EnforcementRuleMode = "max-security"` - `ID string` The read-only identifier that Cloudflare assigns to the rule. - `Description string` An informative description of the rule. - `Enabled bool` Whether the rule is active. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/precursor" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) precursorConfig, err := client.Precursor.Update(context.TODO(), precursor.PrecursorUpdateParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), PrecursorConfig: precursor.PrecursorConfigParam{ }, }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", precursorConfig.DefaultMode) } ``` #### 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" } } ], "success": true, "result": { "default_mode": "min-friction", "enforcement_rules": [ { "expression": "http.request.uri.path eq \"/shop\"", "mode": "max-security", "id": "3a03d665bac043e3a684e0d385a4b1e2", "description": "Enforce max-security on the shop page", "enabled": true } ] } } ``` ## Domain Types ### Enforcement Rule - `type EnforcementRule struct{…}` - `Expression string` The filter expression that determines which requests the rule matches. - `Mode EnforcementRuleMode` The override mode Precursor applies to requests matching an enforcement rule. Unlike `default_mode`, this cannot be `off`. - `const EnforcementRuleModeMinFriction EnforcementRuleMode = "min-friction"` - `const EnforcementRuleModeMaxSecurity EnforcementRuleMode = "max-security"` - `ID string` The read-only identifier that Cloudflare assigns to the rule. - `Description string` An informative description of the rule. - `Enabled bool` Whether the rule is active. ### Precursor Config - `type PrecursorConfig struct{…}` - `DefaultMode PrecursorConfigDefaultMode` The zone-level Precursor enforcement mode applied to requests that do not match a more specific enforcement rule. - `const PrecursorConfigDefaultModeOff PrecursorConfigDefaultMode = "off"` - `const PrecursorConfigDefaultModeMinFriction PrecursorConfigDefaultMode = "min-friction"` - `const PrecursorConfigDefaultModeMaxSecurity PrecursorConfigDefaultMode = "max-security"` - `EnforcementRules []EnforcementRule` The ordered list of enforcement rules for the zone. - `Expression string` The filter expression that determines which requests the rule matches. - `Mode EnforcementRuleMode` The override mode Precursor applies to requests matching an enforcement rule. Unlike `default_mode`, this cannot be `off`. - `const EnforcementRuleModeMinFriction EnforcementRuleMode = "min-friction"` - `const EnforcementRuleModeMaxSecurity EnforcementRuleMode = "max-security"` - `ID string` The read-only identifier that Cloudflare assigns to the rule. - `Description string` An informative description of the rule. - `Enabled bool` Whether the rule is active.