Skip to content
Start here

Update an IP Access rule

client.firewall.accessRules.edit(stringruleId, AccessRuleEditParams { configuration, mode, account_id, 2 more } params, RequestOptionsoptions?): AccessRuleEditResponse { id, allowed_modes, configuration, 5 more }
PATCH/{accounts_or_zones}/{account_or_zone_id}/firewall/access_rules/rules/{rule_id}

Updates an IP Access rule defined.

Note: This operation will affect all zones in the account or zone.

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 Write
ParametersExpand Collapse
ruleId: string

Unique identifier for a rule.

maxLength32
params: AccessRuleEditParams { configuration, mode, account_id, 2 more }
configuration: AccessRuleIPConfiguration { target, value } | IPV6Configuration { target, value } | AccessRuleCIDRConfiguration { target, value } | 2 more

Body param: The rule configuration.

One of the following:
AccessRuleIPConfiguration { target, value }
target?: "ip"

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

value?: string

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

IPV6Configuration { target, value }
target?: "ip6"

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

value?: string

The IPv6 address to match.

AccessRuleCIDRConfiguration { target, value }
target?: "ip_range"

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

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.

ASNConfiguration { target, value }
target?: "asn"

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

value?: string

The AS number to match.

CountryConfiguration { target, value }
target?: "country"

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

value?: string

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

mode: "block" | "challenge" | "whitelist" | 2 more

Body param: The action to apply to a matched request.

One of the following:
"block"
"challenge"
"whitelist"
"js_challenge"
"managed_challenge"
account_id?: string

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

zone_id?: string

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

notes?: string

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

ReturnsExpand Collapse
AccessRuleEditResponse { id, allowed_modes, configuration, 5 more }
id: string

The unique identifier of the IP Access rule.

maxLength32
allowed_modes: Array<"block" | "challenge" | "whitelist" | 2 more>

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

One of the following:
"block"
"challenge"
"whitelist"
"js_challenge"
"managed_challenge"
configuration: AccessRuleIPConfiguration { target, value } | IPV6Configuration { target, value } | AccessRuleCIDRConfiguration { target, value } | 2 more

The rule configuration.

One of the following:
AccessRuleIPConfiguration { target, value }
target?: "ip"

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

value?: string

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

IPV6Configuration { target, value }
target?: "ip6"

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

value?: string

The IPv6 address to match.

AccessRuleCIDRConfiguration { target, value }
target?: "ip_range"

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

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.

ASNConfiguration { target, value }
target?: "asn"

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

value?: string

The AS number to match.

CountryConfiguration { target, value }
target?: "country"

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

value?: string

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

mode: "block" | "challenge" | "whitelist" | 2 more

The action to apply to a matched request.

One of the following:
"block"
"challenge"
"whitelist"
"js_challenge"
"managed_challenge"
created_on?: string

The timestamp of when the rule was created.

formatdate-time
modified_on?: string

The timestamp of when the rule was last modified.

formatdate-time
notes?: string

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

scope?: Scope { id, email, type }

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

id?: string

Defines an identifier.

maxLength32
email?: string

The contact email address of the user.

maxLength90
type?: "user" | "organization"

Defines the scope of the rule.

One of the following:
"user"
"organization"

Update an IP Access rule

import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});

const response = await client.firewall.accessRules.edit('023e105f4ecef8ad9ca31a8372d0c353', {
  configuration: {},
  mode: 'challenge',
  account_id: 'account_id',
});

console.log(response.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
}