Analytics API

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.
9 Replies
matyu
matyuOP3y ago
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"
}
}
}
{ "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"}}]}
{"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"}}]}
{"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
{"data":{"viewer":{"zones":[{"apiGatewayGraphqlQueryAnalyticsGroups":[]}]}},"errors":null}
{"data":{"viewer":{"zones":[{"apiGatewayGraphqlQueryAnalyticsGroups":[]}]}},"errors":null}
Did I make something wrong?
Chaika
Chaika3y ago
You want zone analytics of http requests via GraphQL? 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
Chaika
Chaika3y ago
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
}
}
}
}
}
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
}
}
}
}
}
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/
GraphQL - Cloudflare Datamining
Discover Cloudflare's full GraphQL Schema
matyu
matyuOP3y ago
Yes, particulary this data
matyu
matyuOP3y ago
No just the free plan 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"}}]}
{"data":null,"errors":[{"message":"not authorized for that account","path":null,"extensions":{"code":"authz","timestamp":"2023-05-21T14:18:46.248882016Z"}}]}
Chaika
Chaika3y ago
yes, under Account ID I would double check you didn't put in Zone ID for Account ID /somehow messed it up 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
}
}
}
}
}
{
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
matyu
matyuOP3y ago
{
"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"
}
}
}
{
"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 Thanks Just this data? (Sorry about 'dumb' question but I don't find any information about this in the documentation or in the internet)
Chaika
Chaika3y ago
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/
GraphQL - Cloudflare Datamining
Discover Cloudflare's full GraphQL Schema
Chaika
Chaika3y ago
I used Dev Tools on the free analytics page to find the GraphQL Query it was making, found it was using the dataset httpRequests1dGroups, and then I used GraphiQL's schema introspection to discover all of the fields on it

Did you find this page helpful?