本示例使用 GraphQL Analytics API 在指定时间段内查询 Email Routing 事件。
以下 API 调用将请求一天的 Email Routing 活动日志,并输出所请求的字段。请确保将 <CLOUDFLARE_ZONE_TAG> 和 <API_TOKEN>1 替换为您的 zone tag 和 API 凭据,并根据需要调整 datetime_geg 和 datetime_leq 值。
echo '{ "query":
"query EmailRoutingActivity($zoneTag: string, $filter: EmailRoutingAdaptiveFilter_InputObject) {
viewer {
zones(filter: { zoneTag: $zoneTag }) {
emailRoutingAdaptive(
filter: $filter
limit: 3
orderBy: [datetime_DESC]
) {
datetime
id: sessionId
messageId
from
to
subject
status
action
spf
dkim
dmarc
arc
errorDetail
isNDR
isSpam
spamThreshold
spamScore
}
}
}
}",
"variables": {
"zoneTag": "<CLOUDFLARE_ZONE_TAG>",
"filter": {
"datetime_geq": "2026-01-18T11:00:00Z",
"datetime_leq": "2026-01-19T11:00:00Z"
}
}
}' | tr -d '\n' | curl --silent \
https://api.cloudflare.com/client/v4/graphql \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data @- | jq .返回的结果将以 JSON 格式呈现(如请求所示):
{
"data": {
"viewer": {
"zones": [
{
"emailRoutingAdaptive": [
{
"action": "forward",
"arc": "none",
"datetime": "2026-01-19T10:51:25Z",
"dkim": "pass",
"dmarc": "pass",
"errorDetail": "",
"from": "John <john@email.example.com>",
"id": "AfWyaZ7V1TAH",
"isNDR": 0,
"isSpam": 0,
"messageId": "<9e6574f1-97f8-4060-ad62-c54b6408ac3f@local>",
"spamScore": 0,
"spamThreshold": 5,
"spf": "pass",
"status": "delivered",
"subject": "How are you doing?",
"to": "me@example.com"
},
{
"action": "forward",
"arc": "none",
"datetime": "2026-01-19T10:30:00Z",
"dkim": "pass",
"dmarc": "pass",
"errorDetail": "",
"from": "eBay <ebay@ebay.co.uk>",
"id": "aYPegrIfLWia",
"isNDR": 0,
"isSpam": 0,
"messageId": "<1A513C40-F2CD808A928-029BBE999993-0000000000FA8855@starship>",
"spamScore": 0,
"spamThreshold": 5,
"spf": "pass",
"status": "delivered",
"subject": "New offers",
"to": "me@example.com"
},
{
"action": "forward",
"arc": "none",
"datetime": "2026-01-19T10:29:59Z",
"dkim": "pass",
"dmarc": "pass",
"errorDetail": "",
"from": "Notification <notifications@example.com>",
"id": "nWIl9gs95mY3",
"isNDR": 0,
"isSpam": 0,
"messageId": "<0AB8F1C3-3015EDF2980-019BBE9B58F2-0000000000FA7C4D@local>",
"spamScore": 0,
"spamThreshold": 5,
"spf": "pass",
"status": "delivered",
"subject": "You're over quota",
"to": "me@example.com"
}
]
}
]
}
},
"errors": null
}以下 API 调用将按小时统计事件数量。
echo '{ "query":
"query EmailRoutingActivity($zoneTag: string, $filter: EmailRoutingAdaptiveFilter_InputObject) {
viewer {
zones(filter: { zoneTag: $zoneTag }) {
emailRoutingAdaptiveGroups(
limit: 10000
filter: $filter
orderBy: [datetimeHour_ASC]
) { count
dimensions {
datetimeHour
}
}
}
}
}",
"variables": {
"zoneTag": "<CLOUDFLARE_ZONE_TAG>",
"filter": {
"datetimeHour_geq": "2026-01-18T11:00:00Z",
"datetimeHour_leq": "2026-01-19T11:00:00Z"
}
}
}' | tr -d '\n' | curl --silent \
https://api.cloudflare.com/client/v4/graphql \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data @- | jq .返回的结果将以 JSON 格式呈现(如请求所示):
{
"data": {
"viewer": {
"zones": [
{
"emailRoutingAdaptiveGroups": [
{
"count": 2,
"dimensions": {
"datetimeHour": "2026-01-18T11:00:00Z"
}
},
{
"count": 1,
"dimensions": {
"datetimeHour": "2026-01-18T12:00:00Z"
}
},
{
"count": 1,
"dimensions": {
"datetimeHour": "2026-01-18T13:00:00Z"
}
},
{
"count": 2,
"dimensions": {
"datetimeHour": "2026-01-18T14:00:00Z"
}
},
{
"count": 1,
"dimensions": {
"datetimeHour": "2026-01-18T15:00:00Z"
}
},
{
"count": 1,
"dimensions": {
"datetimeHour": "2026-01-18T16:00:00Z"
}
},
{
"count": 2,
"dimensions": {
"datetimeHour": "2026-01-18T17:00:00Z"
}
},
{
"count": 3,
"dimensions": {
"datetimeHour": "2026-01-18T18:00:00Z"
}
},
{
"count": 1,
"dimensions": {
"datetimeHour": "2026-01-18T22:00:00Z"
}
},
{
"count": 2,
"dimensions": {
"datetimeHour": "2026-01-19T01:00:00Z"
}
},
{
"count": 1,
"dimensions": {
"datetimeHour": "2026-01-19T02:00:00Z"
}
},
{
"count": 4,
"dimensions": {
"datetimeHour": "2026-01-19T05:00:00Z"
}
},
{
"count": 1,
"dimensions": {
"datetimeHour": "2026-01-19T08:00:00Z"
}
},
{
"count": 5,
"dimensions": {
"datetimeHour": "2026-01-19T09:00:00Z"
}
},
{
"count": 6,
"dimensions": {
"datetimeHour": "2026-01-19T10:00:00Z"
}
},
{
"count": 2,
"dimensions": {
"datetimeHour": "2026-01-19T11:00:00Z"
}
}
]
}
]
}
},
"errors": null
}-
有关配置和权限的更多信息,请参阅 Configure an Analytics API token。 ↩