Querying Magic Firewall Samples with GraphQL · Cloudflare Analytics docs | Latest TMZ Celebrity News & Gossip | Watch TMZ Live Skip to content
Cloudflare Docs

Querying Magic Firewall Samples with GraphQL

In this example, we are going to use the GraphQL Analytics API to query for Magic Firewall Samples over a specified time period.

The following API call will request Magic Firewall Samples over a one hour period, and output the requested fields. Be sure to replace <CLOUDFLARE_ACCOUNT_TAG> and <API_TOKEN>1 with your zone tag and API credentials, and adjust the datetime_geg and datetime_leq values to your liking.

API Call

Terminal window
echo '{ "query":
"query MFWActivity {
viewer {
accounts(filter: { accountTag: $accountTag }) {
magicFirewallSamplesAdaptiveGroups(
filter: $filter
limit: 10
orderBy: [datetimeFiveMinute_DESC]
) {
sum {
bits
packets
}
dimensions {
datetimeFiveMinute
ruleId
}
}
}
}
}",
"variables": {
"accountTag": "<CLOUDFLARE_ACCOUNT_TAG>",
"filter": {
"datetime_geq": "2022-07-24T11:00:00Z",
"datetime_leq": "2022-07-24T11:10: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 @-

The returned values represent the total number of packets and bits received during the five minute interval for a particular rule. The result will be in JSON (as requested), so piping the output to jq will make it easier to read, like in the following example:

Terminal window
... | 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 .
#=> {
#=> "data": {
#=> "viewer": {
#=> "accounts": [
#=> {
#=> "magicFirewallSamplesAdaptiveGroups": [
#=> {
#=> sum: { bits: 327680, packets: 16384 },
#=> dimensions: {
#=> datetimeFiveMinute: '2021-05-12T22:00-00:00',
#=> ruleId: 'bdfa8f8f0ae142b4a70ef15f6160e532'
#=> }
#=> },
#=> {
#=> sum: { bits: 360448, packets: 8192 },
#=> dimensions: {
#=> datetimeFiveMinute: '2021-05-12T22:05-00:00',
#=> ruleId: 'bdfa8f8f0ae142b4a70ef15f6160e532'
#=> }
#=> },
#=> {
#=> sum: { bits: 327680, packets: 8192 },
#=> dimensions: {
#=> datetimeFiveMinute: '2021-05-12T22:05-00:00',
#=> ruleId: 'bdfa8f8f0ae142b4a70ef15f6160e532'
#=> }
#=> },
#=> {
#=> sum: { bits: 360448, packets: 8192 },
#=> dimensions: {
#=> datetimeFiveMinute: '2021-05-12T22:20-00:00',
#=> ruleId: 'bdfa8f8f0ae142b4a70ef15f6160e532'
#=> }
#=> },
#=> {
#=> sum: { bits: 327680, packets: 8192 },
#=> dimensions: {
#=> datetimeFiveMinute: '2021-05-12T22:20-00:00',
#=> ruleId: 'bdfa8f8f0ae142b4a70ef15f6160e532'
#=> }
#=> }
#=> ]
#=> }
#=> ]
#=> }
#=> },
#=> "errors": null
#=> }

Footnotes

  1. Refer to Configure an Analytics API token for more information on configuration and permissions.

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.