跳转到内容
搜索文档

常用 API 调用

最后更新 查看 MarkdownAgent 设置

以下示例介绍了使用 Cloudflare API 管理和配置泄露凭据检测的常用方案。

如果您使用的是 Terraform,请参阅 Terraform 配置示例

常规操作

以下 API 示例涵盖了启用和禁用泄露凭据检测等基本操作。

开启泄露凭据检测

要开启泄露凭据检测,请使用类似于以下的 POST 请求:

Required API token permissions

At least one of the following token permissions is required:
  • Zone WAF Write
  • Account WAF Write
Set Leaked Credential Checks Statusbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/leaked-credential-checks" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"enabled": true
	}'

关闭泄露凭据检测

要关闭泄露凭据检测,请使用类似于以下的 POST 请求:

Required API token permissions

At least one of the following token permissions is required:
  • Zone WAF Write
  • Account WAF Write
Set Leaked Credential Checks Statusbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/leaked-credential-checks" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"enabled": false
	}'

获取泄露凭据检测状态

要获取泄露凭据检测的当前状态,请使用类似于以下的 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 Leaked Credential Checks Statusbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/leaked-credential-checks" \
	--request GET \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
{
	"result": {
		"enabled": true
	},
	"success": true,
	"errors": [],
	"messages": []
}

自定义检测位置操作

以下 API 示例涵盖了针对泄露凭据检测的 自定义检测位置 的操作。

添加自定义检测位置

要添加自定义检测位置,请使用类似于以下的 POST 请求:

Required API token permissions

At least one of the following token permissions is required:
  • Zone WAF Write
  • Account WAF Write
Create Leaked Credential Checks Custom Detectionbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/leaked-credential-checks/detections" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"username": "lookup_json_string(http.request.body.raw, \"user\")",
		"password": "lookup_json_string(http.request.body.raw, \"secret\")"
	}'

获取现有的自定义检测位置

要获取现有自定义检测位置的列表,请使用类似于以下的 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 Leaked Credential Checks Custom Detectionsbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/leaked-credential-checks/detections" \
	--request GET \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
{
	"result": [
		{
			"id": "<DETECTION_ID>",
			"username": "lookup_json_string(http.request.body.raw, \"user\")",
			"password": "lookup_json_string(http.request.body.raw, \"secret\")"
		}
		// (...)
	],
	"success": true,
	"errors": [],
	"messages": []
}

删除自定义检测位置

要删除自定义检测位置,请使用类似于以下的 DELETE 请求:

Required API token permissions

At least one of the following token permissions is required:
  • Zone WAF Write
  • Account WAF Write
Delete Leaked Credential Checks Custom Detectionbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/leaked-credential-checks/detections/$DETECTION_ID" \
	--request DELETE \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"

这篇文档对您有帮助吗?