#Analytics API

1 messages · Page 1 of 1 (latest)

keen vault
#

Hi Everyone, since last week I try to get Analytics of my domain but I totally don't understand how the API and how GraphQL works... Can you help me please?
Thanks
ps: Sorry for my bad English.

keen vault
#

Ok so I tried a lot of things. Here’s where I am:
My query: ```
{ "query":
"{
viewer {
zones(filter: { zoneTag: $zoneTag }) {
apiGatewayGraphqlQueryAnalyticsGroups(filter: $filter) {
avg
count
dimensions
}
}
}
}",
"variables": {
"zoneTag": "",
"filter": {
"limit": 100,
"datetime_geq": "2023-05-19T11:00:00Z",
"datetime_leq": "2022-05-19T12:00:00Z"
}
}
}

The API response: 
```{"data":null,"errors":[{"message":"error parsing args for \"apiGatewayGraphqlQueryAnalyticsGroups\": limit: not a number","path":null,"extensions":{"timestamp":"2023-05-19T16:56:43.456792421Z"}}]}```
#

I think it's just a dumb problem, but I don't understand why it's doing this

#

oh very dumb, the limit argument is not in the filter

#

Now I have this:
{"data":null,"errors":[{"message":"object field must have selections","path":null,"extensions":{"timestamp":"2023-05-19T17:07:23.093934081Z"}}]}

#

Ok I found a solution

#

but

#

Did I make something wrong?

rose saddle
#

Do you have Pro (Web Traffic Analytics) or higher? Otherwise the datasets you can get are limited. You can get account-aggregated stats if that's also fine

#

example for simple account-wide analytics:

query {
  viewer {
    accounts(filter: { accountTag: "b9e510810e1e12fcd40826d266a1fb12"}) {
      httpRequestsOverviewAdaptiveGroups(filter: { date_gt: "2023-05-14"}, limit: 1000) {
        sum {
          requests
          cachedRequests,
          bytes
        }
      }
    }
  }
}

grouped by hour

query {
  viewer {
    accounts(filter: { accountTag: "b9e510810e1e12fcd40826d266a1fb12"}) {
      httpRequestsOverviewAdaptiveGroups(filter: { date_gt: "2023-05-14"}, limit: 1000) {
        sum {
          requests
          cachedRequests,
          bytes
        }
        dimensions {
          datetimeHour
        }
      }
    }
  }
}

Replace Acct Id with your own
Use something like GraphiQL for schema introspection, helps a lot. The GraphQL Schema data is also online at https://cfdata.lol/graphql/

keen vault
keen vault
#

My Account ID is on the Overview page?

#

Because if I use it, the server responds this:

{"data":null,"errors":[{"message":"not authorized for that account","path":null,"extensions":{"code":"authz","timestamp":"2023-05-21T14:18:46.248882016Z"}}]}
rose saddle
rose saddle
rose saddle
# keen vault No just the free plan

On free, you still have access to some of the datasets. Looks like free analytics just pull from httpRequests1dGroups, ex

{
  viewer {
    zones(filter: {zoneTag: "37f04f6e8d1e10349acd2cd00eb306bb"}) {
      httpRequests1dGroups(filter: { date_gt: "2023-05-20"}, limit: 10000) {
        sum {
          cachedBytes
          cachedRequests
          requests
          encryptedBytes
          threats
          pageViews
          responseStatusMap {
            requests
            edgeResponseStatus
          }
          browserMap {
            uaBrowserFamily
            pageViews
          }
          ipClassMap {
            ipType
            requests
          }
          threatPathingMap {
            threatPathingName
            requests
          }
        }
        avg {
          sampleInterval
        }
        uniq {
          uniques
        }
      }
    }
  }
}

(that's a zone data/set needs Zone ID, not an account id

keen vault
# rose saddle I would double check you didn't put in Zone ID for Account ID /somehow messed it...
  "query": "query {
    viewer {
      accounts(filter: { accountTag: $accountTag}) {
        httpRequestsOverviewAdaptiveGroups(filter: { date_gt: \"2023-05-14\"}, limit: 1000) {
          sum {
            requests
            cachedRequests
            bytes
          }
        }
      }
    }
  }",
  "variables": {
    "zoneTag": "0eb57270a7e86ddf27a47c69ac6a90f9",
    "accountTag": "f0d752b608af7d0874fceddd712cee27",
    "filter": {
      "datetime_geq": "2023-05-19T03:00:00Z",
      "datetime_leq": "2023-05-19T03:10:00Z"
    }
  }
}``` Here is my entire query with zoneTag and accountTag
keen vault
#

Just this data?

#

(Sorry about 'dumb' question but I don't find any information about this in the documentation or in the internet)

rose saddle
# keen vault (Sorry about 'dumb' question but I don't find any information about this in the ...

GraphQL has a schema you can explore to get information on all of the datasets/types

You can use a client like GraphiQL which has schema introspection to help you out (https://developers.cloudflare.com/analytics/graphql-api/getting-started/compose-graphql-query/), as well as using the Dev Tools Network Tab (look for requests for the file graphql) to find the datasets/use the queries the dashboard uses as a starting point. There's a nicely formatted community website here also showing the graphql schema: https://cfdata.lol/graphql/