To make your first request to Cloudflare’s Radar API, you must obtain your API token first. Create a Custom Token, with User > User Details in the Permissions group, and select Read as the access level.
Once you have the token, you are ready to make your first request to Radar’s API at https://api.cloudflare.com/client/v4/radar/.
Example using cURL
In the following example, we will access the global percentage distribution of device types (like mobile and desktop traffic) for the last seven days. For more information, refer to Get device types summary endpoint:
A successful response will look similar to the following:
This response means that 41% of the requests are classified as coming from mobile devices, while 58% are desktop traffic.
The previous example returns all traffic from bots and humans. However, you can access just the traffic classified as coming from humans (the default in Cloudflare Radar ↗) by adding botClass=LIKELY_HUMAN. You can also access traffic coming only from bots with botClass=LIKELY_AUTOMATED (refer to bot classes for more information). For example:
Running the above, can you find any differences between both in the distribution of mobile versus desktop traffic?
Use Python
Python ↗ has become one of the standard languages in data analysis. Here is a quick example on how to chart the same data using Requests ↗ and Pandas ↗ libraries. Here, we are using format=csv in the parameters to make it easier for Pandas to import.
Notebooks
A notebook ↗ is a web-based interactive computing application, where text, code, and code outputs, like charts, can be combined into a single document. Refer to Radar’s companion colaboratory notebook ↗ for more examples on how the API can be used in your own projects.