Fetching bulk analytics : problem with cURL request provided by the doc


I’m building an application around Cloudflare stream and I have some troubles with the Fetching bulk analytics documentation.

The cURL request provided just does not work : (I of course changed the $TOKEN and $ACCOUNT_ID and the authentication is O.K.)

curl --request POST \--url https://api.cloudflare.com/client/v4/graphql \--header 'content-type: application/json' \--header 'Authorization: Bearer $TOKEN' \--data '{"query":"query {\n  viewer {\n    accounts(filter:{\n      accountTag:\"$ACCOUNT_ID\"\n\n    }) {\n      videoPlaybackEventsAdaptiveGroups(\n        filter: {\n          date_geq: \"2020-09-01\"\n          date_lt: \"2020-09-25\"\n        }\n        orderBy:[uid_ASC]\n        limit: 10000\n      ) {\n        count\n        sum {\n          timeViewedMinutes\n        }\n        dimensions{\n          uid\n        }\n      }\n    }\n  }\n}\n\n"}'

However, I get this error :

    "data": null,
    "errors": [{
        "message": "failed to recognize JSON request: 'invalid character '5' after object key:value pair'",
        "path": null,
        "extensions": {
            "timestamp": "2021-03-14T19:12:21.038542487Z"

And when I try to validate the GraphQL from the exemple, I also have an error :

I just can’t get around this problem. Any help will be greatly appreciated!

After several hours, I finally succeeded :grimacing:! I use the API with PHP and mixing json with GraphQL is not that easy because of double quotes around both languages.

  1. I had to put my CURL data around double quote and not simple quote to get the json working
  2. I had to create a second token with different authorizations. For whatever reason, a token with only “Streams:edit” is not enough.

To all the Cloudflare team, I beg you, write more examples in Cloudflare Stream documentation.