## Create a User Agent Blocking rule `client.Firewall.UARules.New(ctx, params) (*UARuleNewResponse, error)` **post** `/zones/{zone_id}/firewall/ua_rules` Creates a new User Agent Blocking rule in a zone. ### Parameters - `params UARuleNewParams` - `ZoneID param.Field[string]` Path param: Defines an identifier. - `Configuration param.Field[UARuleNewParamsConfiguration]` Body param - `Target UARuleNewParamsConfigurationTarget` The configuration target. You must set the target to `ua` when specifying a user agent in the rule. - `const UARuleNewParamsConfigurationTargetUA UARuleNewParamsConfigurationTarget = "ua"` - `Value string` the user agent to exactly match - `Mode param.Field[UARuleNewParamsMode]` Body param: The action to apply to a matched request. - `const UARuleNewParamsModeBlock UARuleNewParamsMode = "block"` - `const UARuleNewParamsModeChallenge UARuleNewParamsMode = "challenge"` - `const UARuleNewParamsModeWhitelist UARuleNewParamsMode = "whitelist"` - `const UARuleNewParamsModeJSChallenge UARuleNewParamsMode = "js_challenge"` - `const UARuleNewParamsModeManagedChallenge UARuleNewParamsMode = "managed_challenge"` - `Description param.Field[string]` Body param: An informative summary of the rule. This value is sanitized and any tags will be removed. - `Paused param.Field[bool]` Body param: When true, indicates that the rule is currently paused. ### Returns - `type UARuleNewResponse struct{…}` - `ID string` The unique identifier of the User Agent Blocking rule. - `Configuration UARuleNewResponseConfiguration` The configuration object for the current rule. - `Target string` The configuration target for this rule. You must set the target to `ua` for User Agent Blocking rules. - `Value string` The exact user agent string to match. This value will be compared to the received `User-Agent` HTTP header value. - `Description string` An informative summary of the rule. - `Mode UARuleNewResponseMode` The action to apply to a matched request. - `const UARuleNewResponseModeBlock UARuleNewResponseMode = "block"` - `const UARuleNewResponseModeChallenge UARuleNewResponseMode = "challenge"` - `const UARuleNewResponseModeJSChallenge UARuleNewResponseMode = "js_challenge"` - `const UARuleNewResponseModeManagedChallenge UARuleNewResponseMode = "managed_challenge"` - `Paused bool` When true, indicates that the rule is currently paused. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/firewall" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) uaRule, err := client.Firewall.UARules.New(context.TODO(), firewall.UARuleNewParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), Configuration: cloudflare.F(firewall.UARuleNewParamsConfiguration{ }), Mode: cloudflare.F(firewall.UARuleNewParamsModeChallenge), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", uaRule.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": { "id": "372e67954025e0ba6aaa6d586b9e0b59", "configuration": { "target": "ua", "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4" }, "description": "Prevent access from abusive clients identified by this User Agent to mitigate a DDoS attack", "mode": "js_challenge", "paused": false }, "success": true } ```