Skip to content
Start here

Get an IP Access rule

client.Firewall.AccessRules.Get(ctx, ruleID, query) (*AccessRuleGetResponse, error)
GET/{accounts_or_zones}/{account_or_zone_id}/firewall/access_rules/rules/{rule_id}

Fetches the details of an IP Access rule defined.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Account Firewall Access Rules WriteAccount Firewall Access Rules Read
ParametersExpand Collapse
ruleID string

Unique identifier for a rule.

maxLength32
query AccessRuleGetParams
AccountID param.Field[string]optional

The Account ID to use for this endpoint. Mutually exclusive with the Zone ID.

ZoneID param.Field[string]optional

The Zone ID to use for this endpoint. Mutually exclusive with the Account ID.

ReturnsExpand Collapse
type AccessRuleGetResponse struct{…}
ID string

The unique identifier of the IP Access rule.

maxLength32
AllowedModes []AccessRuleGetResponseAllowedMode

The available actions that a rule can apply to a matched request.

One of the following:
const AccessRuleGetResponseAllowedModeBlock AccessRuleGetResponseAllowedMode = "block"
const AccessRuleGetResponseAllowedModeChallenge AccessRuleGetResponseAllowedMode = "challenge"
const AccessRuleGetResponseAllowedModeWhitelist AccessRuleGetResponseAllowedMode = "whitelist"
const AccessRuleGetResponseAllowedModeJSChallenge AccessRuleGetResponseAllowedMode = "js_challenge"
const AccessRuleGetResponseAllowedModeManagedChallenge AccessRuleGetResponseAllowedMode = "managed_challenge"
Configuration AccessRuleGetResponseConfiguration

The rule configuration.

One of the following:
type AccessRuleIPConfiguration struct{…}
Target AccessRuleIPConfigurationTargetoptional

The configuration target. You must set the target to ip when specifying an IP address in the rule.

Value stringoptional

The IP address to match. This address will be compared to the IP address of incoming requests.

type IPV6Configuration struct{…}
Target IPV6ConfigurationTargetoptional

The configuration target. You must set the target to ip6 when specifying an IPv6 address in the rule.

Value stringoptional

The IPv6 address to match.

type AccessRuleCIDRConfiguration struct{…}
Target AccessRuleCIDRConfigurationTargetoptional

The configuration target. You must set the target to ip_range when specifying an IP address range in the rule.

Value stringoptional

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 ASNConfigurationTargetoptional

The configuration target. You must set the target to asn when specifying an Autonomous System Number (ASN) in the rule.

Value stringoptional

The AS number to match.

type CountryConfiguration struct{…}
Target CountryConfigurationTargetoptional

The configuration target. You must set the target to country when specifying a country code in the rule.

Value stringoptional

The two-letter ISO-3166-1 alpha-2 code to match. For more information, refer to IP Access rules: Parameters.

Mode AccessRuleGetResponseMode

The action to apply to a matched request.

One of the following:
const AccessRuleGetResponseModeBlock AccessRuleGetResponseMode = "block"
const AccessRuleGetResponseModeChallenge AccessRuleGetResponseMode = "challenge"
const AccessRuleGetResponseModeWhitelist AccessRuleGetResponseMode = "whitelist"
const AccessRuleGetResponseModeJSChallenge AccessRuleGetResponseMode = "js_challenge"
const AccessRuleGetResponseModeManagedChallenge AccessRuleGetResponseMode = "managed_challenge"
CreatedOn Timeoptional

The timestamp of when the rule was created.

formatdate-time
ModifiedOn Timeoptional

The timestamp of when the rule was last modified.

formatdate-time
Notes stringoptional

An informative summary of the rule, typically used as a reminder or explanation.

Scope AccessRuleGetResponseScopeoptional

All zones owned by the user will have the rule applied.

ID stringoptional

Defines an identifier.

maxLength32
Email stringoptional

The contact email address of the user.

maxLength90
Type AccessRuleGetResponseScopeTypeoptional

Defines the scope of the rule.

One of the following:
const AccessRuleGetResponseScopeTypeUser AccessRuleGetResponseScopeType = "user"
const AccessRuleGetResponseScopeTypeOrganization AccessRuleGetResponseScopeType = "organization"

Get an IP Access rule

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.Get(
    context.TODO(),
    "023e105f4ecef8ad9ca31a8372d0c353",
    firewall.AccessRuleGetParams{

    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", accessRule.ID)
}
{
  "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
}
Returns Examples
{
  "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
}