Skip to content

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

Custom Errors のよく使う API 呼び出し

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

次の各節では、ゾーン単位でカスタムエラーアセットと Error Pages を管理する、よく使う API 呼び出しの例を示します。

同じ操作をアカウント単位で行う場合は、対応するアカウント単位の API エンドポイントを使います。

カスタムエラーアセットを作成する

次の POST リクエストは、指定した URL をもとに、ゾーンにカスタムエラーアセットを新規作成します。

curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_pages/assets" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
  "name": "500_error_template",
  "description": "Standard 5xx error template page",
  "url": "https://example.com/errors/500_template.html"
}'
{
	"result": {
		"name": "500_error_template",
		"description": "Standard 5xx error template page",
		"url": "https://example.com/errors/500_template.html",
		"last_updated": "2025-02-10T11:36:07.810215Z",
		"size_bytes": 2048
	},
	"success": true
}

アカウント単位でアセットを作成する場合は、アカウント単位のエンドポイントを使います。

https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/custom_pages/assets

カスタムエラーアセットを一覧する

次の GET リクエストは、ゾーンに設定されているカスタムエラーアセットの一覧を取得します。

curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_pages/assets" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
{
	"result": [
		{
			"name": "500_error_template",
			"description": "Standard 5xx error template page",
			"url": "https://example.com/errors/500_template.html",
			"last_updated": "2025-02-10T11:36:07.810215Z",
			"size_bytes": 2048
		}
		// ...
	],
	"success": true,
	"errors": [],
	"messages": [],
	"result_info": {
		"count": 2,
		"page": 1,
		"per_page": 20,
		"total_count": 2,
		"total_pages": 1
	}
}

アカウント単位でアセット一覧を取得する場合は、アカウント単位のエンドポイントを使います。

https://api.cloudflare.com/client/v4/accounts/$ZONE_ID/custom_pages/assets

カスタムエラーアセットを更新する

次の PUT リクエストは、ゾーン単位の既存カスタムエラーアセット 500_error_template の URL を更新します。

curl --request PUT \
"https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_pages/assets/500_error_template" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
  "description": "Standard 5xx error template page",
  "url": "https://example.com/errors/500_new_template.html"
}'
{
	"result": {
		"name": "500_error_template",
		"description": "Standard 5xx error template page",
		"url": "https://example.com/errors/500_new_template.html",
		"last_updated": "2025-02-10T13:13:07.810215Z",
		"size_bytes": 3145
	},
	"success": true
}

更新できるのはアセットの説明と URL です。作成後にアセット名は変更できません。

更新時に同じ URL を指定すると、Cloudflare はその URL とリソースを再度取得します。

アカウント単位でアセットを更新する場合は、アカウント単位のエンドポイントを使います。

https://api.cloudflare.com/client/v4/accounts/{account_id}/custom_pages/assets/{asset_name}

カスタムエラーアセットを取得する

次の GET リクエストは、ゾーン単位の既存カスタムエラーアセット 500_error_template の詳細を取得します。

curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_pages/assets/500_error_template" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
{
	"result": {
		"name": "500_error_template",
		"description": "Standard 5xx error template page",
		"url": "https://example.com/errors/500_new_template.html",
		"last_updated": "2025-02-10T13:13:07.810215Z",
		"size_bytes": 3145
	},
	"success": true
}

アカウント単位でアセットを取得する場合は、アカウント単位のエンドポイントを使います。

https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/custom_pages/assets/$ASSET_NAME

カスタムエラーアセットを削除する

次の DELETE リクエストは、ゾーン単位の既存カスタムエラーアセット 500_error_template を削除します。

curl --request DELETE \
"https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_pages/assets/500_error_template" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"

リクエストが成功すると、レスポンスの HTTP ステータスコードは 204 になります。

アカウント単位でアセットを削除する場合は、アカウント単位のエンドポイントを使います。

https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/custom_pages/assets/$ASSET_NAME

エラーページを取得する

この例では、Rate limiting block エラーページ(ID は ratelimit_block)の現在の設定を取得します。

Required API token permissions

At least one of the following token permissions is required:
  • Custom Pages Write
  • Custom Pages Read
  • Zone Settings Write
  • Zone Settings Read
Get a custom pagebash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_IDENTIFIER/custom_pages/ratelimit_block" \
	--request GET \
	--header "X-Auth-Email: $CLOUDFLARE_EMAIL" \
	--header "X-Auth-Key: $CLOUDFLARE_API_KEY"
{
	"result": {
		"id": "ratelimit_block",
		"description": "Rate limit Block",
		"required_tokens": [],
		"preview_target": "block:rate-limit",
		"created_on": "2025-06-03T08:33:17.091587Z",
		"modified_on": "2025-06-03T08:33:17.091587Z",
		"url": null,
		"state": "default"
	},
	"success": true,
	"errors": [],
	"messages": []
}

レスポンスは、ページが現在 Cloudflare のデフォルトページに設定されていること("state": "default")を示しています。

エラーページの識別子一覧は エラーページの種類 を参照してください。

エラーページを更新する

この例では、指定した URL をもとに、Rate limiting block エラー(ID は ratelimit_block)向けのカスタムエラーページを定義します。

Required API token permissions

At least one of the following token permissions is required:
  • Custom Pages Write
  • Zone Settings Write
Update a custom pagebash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_IDENTIFIER/custom_pages/ratelimit_block" \
	--request PUT \
	--header "X-Auth-Email: $CLOUDFLARE_EMAIL" \
	--header "X-Auth-Key: $CLOUDFLARE_API_KEY" \
	--json '{
		"state": "customized",
		"url": "https://example.com/rate_limiting_block_error_page.html"
	}'
{
	"result": {
		"id": "ratelimit_block",
		"description": "Rate limit Block",
		"required_tokens": [],
		"preview_target": "block:rate-limit",
		"created_on": "2025-06-03T08:33:17.091587Z",
		"modified_on": "2025-06-03T08:35:32.639114Z",
		"url": "https://example.com/rate_limiting_block_error_page.html",
		"state": "customized"
	},
	"success": true,
	"errors": [],
	"messages": []
}

エラーページをデフォルトに戻すには、リクエスト本文で "state": "default" を使います。

エラーページの識別子一覧は エラーページの種類 を参照してください。

関連リソース

役に立ちましたか?