指定したフェーズに、指定した種類のルールセットを作成します。フェーズのエントリポイントルールセットも作成できます。
次のいずれかの API エンドポイントを使います。
- Create an account ruleset
POST /accounts/{account_id}/rulesets - Create a zone ruleset
POST /zones/{zone_id}/rulesets
ルールセットを作成する POST リクエストは、リクエスト本文で次のパラメーターをサポートします。
nameString- ルールセットの分かりやすい名前です。
- 名前は変更できません。ルールセットの存続期間中は変えられません。
descriptionString任意- ルールセットの任意の説明です。
- ルールセットの存続期間中に説明は変更できます。
kindString- JSON オブジェクトが表すルールセットの種類です。
- 使用できる値:
custom: カスタムルールセットを作成しますroot: アカウントレベルでフェーズの エントリポイントルールセット を作成しますzone: ゾーンレベルでフェーズのエントリポイントルールセットを作成します
phaseStringrulesArray<Rule>任意- ルールセットに含める ルール の一覧です。
これらのパラメーターの詳細は JSON オブジェクト を参照してください。
次の POST リクエストは、アカウントレベルの http_request_firewall_custom フェーズに、ルールを 1 件含むカスタムルールセットを作成します。
Required API token permissions
At least one of the following token permissions is required:Mass URL Redirects WriteMagic Firewall WriteL4 DDoS Managed Ruleset WriteTransform Rules WriteSelect Configuration WriteAccount WAF WriteAccount Rulesets WriteLogs Write
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/rulesets" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Example custom ruleset",
"kind": "custom",
"description": "Example ruleset description",
"rules": [
{
"action": "log",
"expression": "cf.zone.name eq \"example.com\""
}
],
"phase": "http_request_firewall_custom"
}'{
"result": {
"id": "<RULESET_ID>",
"name": "Example custom ruleset",
"description": "Example ruleset description",
"kind": "custom",
"version": "1",
"rules": [
{
"id": "<RULE_ID>",
"version": "1",
"action": "log",
"expression": "cf.zone.name eq \"example.com\"",
"last_updated": "2025-03-17T15:42:37.917815Z"
}
],
"last_updated": "2025-03-17T15:42:37.917815Z",
"phase": "http_request_firewall_custom"
},
"success": true,
"errors": [],
"messages": []
}次の POST リクエストは、http_request_firewall_managed フェーズにゾーンレベルのフェーズエントリポイントルールセットを作成し、マネージドルールセットを実行するルールを 1 件含めます。
Required API token permissions
At least one of the following token permissions is required:Response Compression WriteConfig Settings WriteDynamic URL Redirects WriteCache Settings WriteCustom Errors WriteOrigin WriteManaged headers WriteZone Transform Rules WriteMass URL Redirects WriteMagic Firewall WriteL4 DDoS Managed Ruleset WriteHTTP DDoS Managed Ruleset WriteSanitize WriteTransform Rules WriteSelect Configuration WriteBot Management WriteZone WAF WriteAccount WAF WriteAccount Rulesets WriteLogs WriteLogs Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Zone-level phase entry point",
"kind": "zone",
"description": "This ruleset executes a managed ruleset.",
"rules": [
{
"action": "execute",
"expression": "true",
"action_parameters": {
"id": "<MANAGED_RULESET_ID>"
}
}
],
"phase": "http_request_firewall_managed"
}'{
"result": {
"id": "<RULESET_ID>",
"name": "Zone-level phase entry point",
"description": "This ruleset executes a managed ruleset.",
"kind": "zone",
"version": "1",
"rules": [
{
"id": "<RULE_ID>",
"version": "1",
"action": "execute",
"expression": "true",
"action_parameters": {
"id": "<MANAGED_RULESET_ID>"
},
"last_updated": "2025-03-17T15:42:37.917815Z"
}
],
"last_updated": "2025-03-17T15:42:37.917815Z",
"phase": "http_request_firewall_managed"
},
"success": true,
"errors": [],
"messages": []
}次の POST リクエストは、http_ratelimit フェーズ向けのアカウントレベルのフェーズエントリポイントルールセットを作成し、アカウント内のすべての Enterprise ゾーンに対してレート制限ルールセットを実行するルールを 1 件含めます。
Required API token permissions
At least one of the following token permissions is required:Mass URL Redirects WriteMagic Firewall WriteL4 DDoS Managed Ruleset WriteTransform Rules WriteSelect Configuration WriteAccount WAF WriteAccount Rulesets WriteLogs Write
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/rulesets" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Account-level phase entry point",
"kind": "root",
"description": "This ruleset executes a rate limiting ruleset.",
"rules": [
{
"action": "execute",
"expression": "(cf.zone.plan eq \"ENT\")",
"action_parameters": {
"id": "<RATE_LIMITING_RULESET_ID>"
}
}
],
"phase": "http_ratelimit"
}'{
"result": {
"id": "<RULESET_ID>",
"name": "Account-level phase entry point",
"description": "This ruleset executes a rate limiting ruleset.",
"kind": "root",
"version": "1",
"rules": [
{
"id": "<RULE_ID>",
"version": "1",
"action": "execute",
"expression": "(cf.zone.plan eq \"ENT\")",
"action_parameters": {
"id": "<RATE_LIMITING_RULESET_ID>"
},
"last_updated": "2024-09-17T15:42:37.917815Z"
}
],
"last_updated": "2024-09-17T15:42:37.917815Z",
"phase": "http_ratelimit"
},
"success": true,
"errors": [],
"messages": []
}