跳转到内容
搜索文档

Log Explorer API

最后更新 查看 MarkdownAgent 设置

配置和日志搜索也可以通过公共 API 进行。

身份验证

使用 API 进行身份验证可以通过 API 令牌或带有电子邮件的 API 密钥来完成。有关进一步说明,请参阅创建 API 令牌

关于每项 Log Explorer 功能所需的权限的详细信息,请参阅 Permissions(权限)部分。

查询数据

Log Explorer 包含一个用于提交查询的 SQL API。

例如,要使用特定的 Ray ID 查找 HTTP 请求,请使用以下 SQL 查询:

curl https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/explorer/query/sql \
--header "Authorization: Bearer <API_TOKEN>" \
--url-query query="SELECT clientRequestScheme, clientRequestHost, clientRequestMethod, edgeResponseStatus, clientRequestUserAgent FROM http_requests WHERE RayID = '806c30a3cec56817' LIMIT 1"

该命令返回以下 HTTP 请求详细信息:

{
	"result": [
		{
			"clientrequestscheme": "https",
			"clientrequesthost": "example.com",
			"clientrequestmethod": "GET",
			"clientrequestuseragent": "curl/7.88.1",
			"edgeresponsestatus": 200
		}
	],
	"success": true,
	"errors": [],
	"messages": []
}

作为另一个示例,您可以通过执行以下 SQL 查询,查找在特定时间段内具有所选列的 Cloudflare Access 请求:

curl https://api.cloudflare.com/client/v4/accounts/{account_id}/logs/explorer/query/sql \
--header "Authorization: Bearer <API_TOKEN>" \
--url-query query="SELECT CreatedAt, AppDomain, AppUUID, Action, Allowed, Country, RayID, Email, IPAddress, UserUID FROM access_requests WHERE Date >= '2025-02-06' AND Date <= '2025-02-06' AND CreatedAt >= '2025-02-06T12:28:39Z' AND CreatedAt <= '2025-02-06T12:58:39Z'"

该命令返回以下请求详细信息:

{
	"result": [
		{
			"createdat": "2025-01-14T18:17:55Z",
			"appdomain": "example.com",
			"appuuid": "a66b4ab0-ccdf-4d60-a6d0-54a59a827d92",
			"action": "login",
			"allowed": true,
			"country": "us",
			"rayid": "90fbb07c0b316957",
			"email": "[email protected]",
			"ipaddress": "1.2.3.4",
			"useruid": "52859e81-711e-4de0-8b31-283336060e79"
		}
	],
	"success": true,
	"errors": [],
	"messages": []
}

这篇文档对您有帮助吗?