Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

よく使う API 呼び出し

最終更新 Markdown で表示Agent セットアップ

次の例は、Cloudflare API で WAF コンテンツスキャンを管理・設定する、よくあるシナリオです。

Terraform を使う場合は、Terraform の設定例 を参照してください。

一般的な操作

次の API 例は、WAF コンテンツスキャンの有効化と無効化など、基本的な操作です。

WAF コンテンツスキャンを有効にする

コンテンツスキャンを有効にするには、次のような POST リクエストを使います。

Required API token permissions

At least one of the following token permissions is required:
  • Zone WAF Write
  • Account WAF Write
Enable Content Scanning for a zone.bash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/content-upload-scan/enable" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"

WAF コンテンツスキャンを無効にする

コンテンツスキャンを無効にするには、次のような POST リクエストを使います。

Required API token permissions

At least one of the following token permissions is required:
  • Zone WAF Write
  • Account WAF Write
Disable Content Scanning for a zone.bash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/content-upload-scan/disable" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"

WAF コンテンツスキャンの状態を取得する

コンテンツスキャン機能の現在の状態を取得するには、次のような GET リクエストを使います。

Required API token permissions

At least one of the following token permissions is required:
  • Zone WAF Write
  • Zone WAF Read
  • Account WAF Write
  • Account WAF Read
Get the Content Scanning status for a zone.bash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/content-upload-scan/settings" \
	--request GET \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"

カスタム式の操作

次の API 例は、コンテンツスキャンのカスタムスキャン式に対する操作です。

既存のカスタムスキャン式を取得する

既存のカスタムスキャン式の一覧を取得するには、次のような GET リクエストを使います。

Required API token permissions

At least one of the following token permissions is required:
  • Zone WAF Write
  • Zone WAF Read
  • Account WAF Write
  • Account WAF Read
List the Content Scanning custom expressions of a zone.bash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/content-upload-scan/payloads" \
	--request GET \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
{
	"result": [
		{
			"id": "<EXPRESSION_ID>",
			"payload": "lookup_json_string(http.request.body.raw, \"file\")"
		}
	],
	"success": true,
	"errors": [],
	"messages": []
}

カスタムスキャン式を追加する

次のような POST リクエストを使います。

Required API token permissions

At least one of the following token permissions is required:
  • Zone WAF Write
  • Account WAF Write
Create Content Scanning custom expressions for a zone.bash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/content-upload-scan/payloads" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '[
		{
				"payload": "lookup_json_string(http.request.body.raw, \"file\")"
		}
	]'

カスタムスキャン式を削除する

次のような DELETE リクエストを使います。

Required API token permissions

At least one of the following token permissions is required:
  • Zone WAF Write
  • Account WAF Write
Delete a Content Scanning custom expression from a zone.bash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/content-upload-scan/payloads/$EXPRESSION_ID" \
	--request DELETE \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"

役に立ちましたか?