コンテンツにスキップ

ルールセットの更新とデプロイ

APIを使用して、ルールセットの基本プロパティ(現在は説明のみ)とルールセット内のルールのリストを更新できます。

次のAPIエンドポイントのいずれかを使用します:

操作メソッド + エンドポイント
アカウントのルールセットを更新PUT /accounts/{account_id}/rulesets/{ruleset_id}
ゾーンのルールセットを更新PUT /zones/{zone_id}/rulesets/{ruleset_id}
アカウントのエントリポイントルールセットを更新PUT /accounts/{account_id}/rulesets/phases/{phase_name}/entrypoint
ゾーンのエントリポイントルールセットを更新PUT /zones/{zone_id}/rulesets/phases/{phase_name}/entrypoint

例 - ルールセットのルールを設定する

このAPIメソッドを使用して、ルールセットのルールを設定します。ルールセットに関連付けたいすべてのルールを各リクエストに含める必要があります。

リクエスト

Terminal window
curl --request PUT \
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"rules": [
{
"action": "execute",
"action_parameters": {
"id": "<MANAGED_RULESET_ID>"
},
"expression": "true"
}
]
}'

レスポンス

{
"result": {
"id": "<RULESET_ID>",
"name": "ゾーンレベルのフェーズエントリポイント",
"description": "このルールセットは管理されたルールセットを実行します。",
"kind": "zone",
"version": "4",
"rules": [
{
"id": "<RULE_ID>",
"version": "2",
"action": "execute",
"expression": "true",
"action_parameters": {
"id": "<MANAGED_RULESET_ID>"
},
"last_updated": "2023-03-17T15:42:37.917815Z"
}
],
"last_updated": "2023-03-17T15:42:37.917815Z",
"phase": "http_request_firewall_managed"
},
"success": true,
"errors": [],
"messages": []
}

例 - ルールセットをデプロイする

ルールセットをデプロイするには、ルールセットを実行する"action": "execute"のルールを作成し、action_parametersフィールドのidパラメータにルールセットIDを追加します。

次の例では、ゾーンの{zone_id}のゾーンレベルhttp_request_firewall_managedフェーズに管理されたルールセットをデプロイします。

リクエスト

Terminal window
curl --request PUT \
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/phases/http_request_firewall_managed/entrypoint \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"rules": [
{
"action": "execute",
"action_parameters": {
"id": "<MANAGED_RULESET_ID>"
},
"expression": "true",
"description": "私のフェーズエントリポイントでCloudflare管理ルールセットを実行"
}
]
}'

レスポンス

{
"result": {
"id": "<ZONE_PHASE_RULESET_ID>",
"name": "ゾーンレベルのフェーズエントリポイント",
"description": "",
"kind": "zone",
"version": "4",
"rules": [
{
"id": "<RULE_ID_1>",
"version": "1",
"action": "execute",
"action_parameters": {
"id": "<MANAGED_RULESET_ID>",
"version": "latest"
},
"expression": "true",
"description": "私のフェーズエントリポイントでCloudflare管理ルールセットを実行",
"last_updated": "2023-03-21T11:02:08.769537Z",
"ref": "<RULE_REF_1>",
"enabled": true
}
],
"last_updated": "2023-03-21T11:02:08.769537Z",
"phase": "http_request_firewall_managed"
},
"success": true,
"errors": [],
"messages": []
}

ルールセットのデプロイに関する詳細は、ルールセットをデプロイするを参照してください。

例 - ルールセットの説明を更新する

このAPIメソッドを使用して、既存のルールセットまたはフェーズエントリポイントの説明を更新できます。

リクエスト

Terminal window
curl --request PUT \
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"description": "私の更新されたフェーズエントリポイント"
}'

レスポンスには、すべてのルールを含む完全なルールセット定義が含まれます。

レスポンス

{
"result": {
"id": "<RULESET_ID>",
"name": "ゾーンエントリポイント",
"description": "私の更新されたフェーズエントリポイント",
"kind": "zone",
"version": "4",
"rules": [
// (...)
],
"last_updated": "2023-03-30T10:49:11.006109Z",
"phase": "http_request_firewall_managed"
},
"success": true,
"errors": [],
"messages": []
}