## Create an IP Access rule `client.Firewall.AccessRules.New(ctx, params) (*AccessRuleNewResponse, error)` **post** `/{accounts_or_zones}/{account_or_zone_id}/firewall/access_rules/rules` Creates a new IP Access rule for an account or zone. The rule will apply to all zones in the account or zone. Note: To create an IP Access rule that applies to a single zone, refer to the [IP Access rules for a zone](#ip-access-rules-for-a-zone) endpoints. ### Parameters - `params AccessRuleNewParams` - `Configuration param.Field[AccessRuleNewParamsConfiguration]` Body param: The rule configuration. - `type AccessRuleIPConfiguration struct{…}` - `Target AccessRuleIPConfigurationTarget` The configuration target. You must set the target to `ip` when specifying an IP address in the rule. - `const AccessRuleIPConfigurationTargetIP AccessRuleIPConfigurationTarget = "ip"` - `Value string` The IP address to match. This address will be compared to the IP address of incoming requests. - `type IPV6Configuration struct{…}` - `Target IPV6ConfigurationTarget` The configuration target. You must set the target to `ip6` when specifying an IPv6 address in the rule. - `const IPV6ConfigurationTargetIp6 IPV6ConfigurationTarget = "ip6"` - `Value string` The IPv6 address to match. - `type AccessRuleCIDRConfiguration struct{…}` - `Target AccessRuleCIDRConfigurationTarget` The configuration target. You must set the target to `ip_range` when specifying an IP address range in the rule. - `const AccessRuleCIDRConfigurationTargetIPRange AccessRuleCIDRConfigurationTarget = "ip_range"` - `Value string` The IP address range to match. You can only use prefix lengths `/16` and `/24` for IPv4 ranges, and prefix lengths `/32`, `/48`, and `/64` for IPv6 ranges. - `type ASNConfiguration struct{…}` - `Target ASNConfigurationTarget` The configuration target. You must set the target to `asn` when specifying an Autonomous System Number (ASN) in the rule. - `const ASNConfigurationTargetASN ASNConfigurationTarget = "asn"` - `Value string` The AS number to match. - `type CountryConfiguration struct{…}` - `Target CountryConfigurationTarget` The configuration target. You must set the target to `country` when specifying a country code in the rule. - `const CountryConfigurationTargetCountry CountryConfigurationTarget = "country"` - `Value string` The two-letter ISO-3166-1 alpha-2 code to match. For more information, refer to [IP Access rules: Parameters](https://developers.cloudflare.com/waf/tools/ip-access-rules/parameters/#country). - `Mode param.Field[AccessRuleNewParamsMode]` Body param: The action to apply to a matched request. - `const AccessRuleNewParamsModeBlock AccessRuleNewParamsMode = "block"` - `const AccessRuleNewParamsModeChallenge AccessRuleNewParamsMode = "challenge"` - `const AccessRuleNewParamsModeWhitelist AccessRuleNewParamsMode = "whitelist"` - `const AccessRuleNewParamsModeJSChallenge AccessRuleNewParamsMode = "js_challenge"` - `const AccessRuleNewParamsModeManagedChallenge AccessRuleNewParamsMode = "managed_challenge"` - `AccountID param.Field[string]` Path param: The Account ID to use for this endpoint. Mutually exclusive with the Zone ID. - `ZoneID param.Field[string]` Path param: The Zone ID to use for this endpoint. Mutually exclusive with the Account ID. - `Notes param.Field[string]` Body param: An informative summary of the rule, typically used as a reminder or explanation. ### Returns - `type AccessRuleNewResponse struct{…}` - `ID string` The unique identifier of the IP Access rule. - `AllowedModes []AccessRuleNewResponseAllowedMode` The available actions that a rule can apply to a matched request. - `const AccessRuleNewResponseAllowedModeBlock AccessRuleNewResponseAllowedMode = "block"` - `const AccessRuleNewResponseAllowedModeChallenge AccessRuleNewResponseAllowedMode = "challenge"` - `const AccessRuleNewResponseAllowedModeWhitelist AccessRuleNewResponseAllowedMode = "whitelist"` - `const AccessRuleNewResponseAllowedModeJSChallenge AccessRuleNewResponseAllowedMode = "js_challenge"` - `const AccessRuleNewResponseAllowedModeManagedChallenge AccessRuleNewResponseAllowedMode = "managed_challenge"` - `Configuration AccessRuleNewResponseConfiguration` The rule configuration. - `type AccessRuleIPConfiguration struct{…}` - `Target AccessRuleIPConfigurationTarget` The configuration target. You must set the target to `ip` when specifying an IP address in the rule. - `const AccessRuleIPConfigurationTargetIP AccessRuleIPConfigurationTarget = "ip"` - `Value string` The IP address to match. This address will be compared to the IP address of incoming requests. - `type IPV6Configuration struct{…}` - `Target IPV6ConfigurationTarget` The configuration target. You must set the target to `ip6` when specifying an IPv6 address in the rule. - `const IPV6ConfigurationTargetIp6 IPV6ConfigurationTarget = "ip6"` - `Value string` The IPv6 address to match. - `type AccessRuleCIDRConfiguration struct{…}` - `Target AccessRuleCIDRConfigurationTarget` The configuration target. You must set the target to `ip_range` when specifying an IP address range in the rule. - `const AccessRuleCIDRConfigurationTargetIPRange AccessRuleCIDRConfigurationTarget = "ip_range"` - `Value string` The IP address range to match. You can only use prefix lengths `/16` and `/24` for IPv4 ranges, and prefix lengths `/32`, `/48`, and `/64` for IPv6 ranges. - `type ASNConfiguration struct{…}` - `Target ASNConfigurationTarget` The configuration target. You must set the target to `asn` when specifying an Autonomous System Number (ASN) in the rule. - `const ASNConfigurationTargetASN ASNConfigurationTarget = "asn"` - `Value string` The AS number to match. - `type CountryConfiguration struct{…}` - `Target CountryConfigurationTarget` The configuration target. You must set the target to `country` when specifying a country code in the rule. - `const CountryConfigurationTargetCountry CountryConfigurationTarget = "country"` - `Value string` The two-letter ISO-3166-1 alpha-2 code to match. For more information, refer to [IP Access rules: Parameters](https://developers.cloudflare.com/waf/tools/ip-access-rules/parameters/#country). - `Mode AccessRuleNewResponseMode` The action to apply to a matched request. - `const AccessRuleNewResponseModeBlock AccessRuleNewResponseMode = "block"` - `const AccessRuleNewResponseModeChallenge AccessRuleNewResponseMode = "challenge"` - `const AccessRuleNewResponseModeWhitelist AccessRuleNewResponseMode = "whitelist"` - `const AccessRuleNewResponseModeJSChallenge AccessRuleNewResponseMode = "js_challenge"` - `const AccessRuleNewResponseModeManagedChallenge AccessRuleNewResponseMode = "managed_challenge"` - `CreatedOn Time` The timestamp of when the rule was created. - `ModifiedOn Time` The timestamp of when the rule was last modified. - `Notes string` An informative summary of the rule, typically used as a reminder or explanation. - `Scope AccessRuleNewResponseScope` All zones owned by the user will have the rule applied. - `ID string` Defines an identifier. - `Email string` The contact email address of the user. - `Type AccessRuleNewResponseScopeType` Defines the scope of the rule. - `const AccessRuleNewResponseScopeTypeUser AccessRuleNewResponseScopeType = "user"` - `const AccessRuleNewResponseScopeTypeOrganization AccessRuleNewResponseScopeType = "organization"` ### 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"), ) accessRule, err := client.Firewall.AccessRules.New(context.TODO(), firewall.AccessRuleNewParams{ Configuration: cloudflare.F[firewall.AccessRuleNewParamsConfigurationUnion](firewall.AccessRuleIPConfigurationParam{ }), Mode: cloudflare.F(firewall.AccessRuleNewParamsModeChallenge), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", accessRule.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": "92f17202ed8bd63d69a66b86a49a8f6b", "allowed_modes": [ "whitelist", "block", "challenge", "js_challenge", "managed_challenge" ], "configuration": { "target": "ip", "value": "198.51.100.4" }, "mode": "challenge", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "notes": "This rule is enabled because of an event that occurred on date X.", "scope": { "id": "023e105f4ecef8ad9ca31a8372d0c353", "email": "user@example.com", "type": "user" } }, "success": true } ```