跳转到内容
搜索文档

PUT examples

最后更新 查看 MarkdownAgent 设置

更新多条规则

此示例使用单个 API 调用更新多条防火墙规则。

您可以在 JSON 对象数组(-d 标志)中包含最多 25 条规则作为批处理更新。该批处理作为事务处理。

Requestbash
curl --request PUT \
"https://api.cloudflare.com/client/v4/zones/{zone_id}/firewall/rules" \
--header "X-Auth-Email: <EMAIL>" \
--header "X-Auth-Key: <API_KEY>" \
--header "Content-Type: application/json" \
--data '[
  {
    "id": "<RULE_ID>",
    "paused": false,
    "description": "Challenge site",
    "action": "challenge",
    "priority": null,
    "filter": {
      "id": "<FILTER_ID>",
      "expression": "not http.request.uri.path matches \"^/api/.*$\"",
      "paused": false,
      "description": "not /api"
    }
  }
]'
Responsejson
{
	"result": [
		{
			"id": "<RULE_ID>",
			"paused": false,
			"description": "Challenge site",
			"action": "challenge",
			"priority": null,
			"filter": {
				"id": "<FILTER_ID>",
				"expression": "not http.request.uri.path matches \"^/api/.*$\"",
				"paused": false,
				"description": "not /api"
			}
		}
	],
	"success": true,
	"errors": [],
	"messages": []
}

更新单条规则

此示例更新 ID 为 {rule_id} 的防火墙规则。

您必须在请求正文中包含以下字段:

  • id
  • action
  • filter.id

所有其他字段均为可选字段。

Requestbash
curl --request PUT \
"https://api.cloudflare.com/client/v4/zones/{zone_id}/firewall/rules/{rule_id}" \
--header "X-Auth-Email: <EMAIL>" \
--header "X-Auth-Key: <API_KEY>" \
--header "Content-Type: application/json" \
--data '{
  "id": "<RULE_ID>",
  "paused": false,
  "description": "Do not challenge login from office IPv6",
  "action": "allow",
  "priority": null,
  "filter": {
    "id": "<FILTER_ID>",
    "expression": "ip.src in {2400:cb00::/32 2803:f800::/32 2c0f:f248::/32 2a06:98c0::/29} and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")",
    "paused": false,
    "description": "Login from office"
  }
}'
Responsejson
{
	"result": {
		"id": "<RULE_ID>",
		"paused": false,
		"description": "Do not challenge login from office IPv6",
		"action": "allow",
		"priority": null,
		"filter": {
			"id": "<FILTER_ID>",
			"expression": "ip.src in {2400:cb00::/32 2803:f800::/32 2c0f:f248::/32 2a06:98c0::/29} and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")",
			"paused": false,
			"description": "Login from office"
		}
	},
	"success": true,
	"errors": [],
	"messages": []
}

这篇文档对您有帮助吗?