此示例使用单个 API 调用更新多条防火墙规则。
您可以在 JSON 对象数组(-d 标志)中包含最多 25 条规则作为批处理更新。该批处理作为事务处理。
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"
}
}
]'{
"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} 的防火墙规则。
您必须在请求正文中包含以下字段:
idactionfilter.id
所有其他字段均为可选字段。
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"
}
}'{
"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": []
}