Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analytics Datas #36

Closed
emresaracoglu opened this issue Nov 7, 2017 · 9 comments
Closed

Analytics Datas #36

emresaracoglu opened this issue Nov 7, 2017 · 9 comments

Comments

@emresaracoglu
Copy link

Hello,

Can I get analytics data via API? If the answer is yes, can you show me a small example of how I can do it?

Thank you

@TylerVigario
Copy link
Contributor

I don't believe it's currently possible, however, I am working on adding just that as it's a needed in a project of mine.

@emresaracoglu
Copy link
Author

Can the information on this page help us?
Is it not possible to get data with CURL?

@thellimist
Copy link
Contributor

@emresaracoglu yes, it is possible to get analytics data by API. The link you provided has a curl example

curl -X GET "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/analytics/dashboard?since=2015-01-01T12:23:00Z&until=2015-01-02T12:23:00Z&continuous=true" \
     -H "X-Auth-Email: user@example.com" \
     -H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
     -H "Content-Type: application/json"

@emresaracoglu
Copy link
Author

I can get the data but there is a big problem this time :)
I do not know how to read a complicated JSON file.

I plan to use a JSON reader for this. Maybe this; JsonReader - @pcrov

How do I read in the best way for JSON?
for example; bandwidth in JSON

$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL,"https://api.cloudflare.com/client/v4/zones/ZoneID/analytics/dashboard?since=2017-11-06T12:23:00Z&until=2017-11-07T12:23:00Z&continuous=true");
	curl_setopt($ch, CURLOPT_POST, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	
	$headers = [
		'X-Auth-Email: Email',
		'X-Auth-Key: Key',
		'Content-Type: application/json'
	];
	
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
	$server_output = curl_exec ($ch);
	curl_close ($ch);

@TylerVigario
Copy link
Contributor

TylerVigario commented Nov 8, 2017

I've added getAnalyticsDashboard() to Zones

You can pull my fork until they add to a release - https://github.com/MeekLogic/cloudflare-php

@emresaracoglu
Copy link
Author

emresaracoglu commented Nov 8, 2017

@MeekLogic That's great work! Thank you for your time.
I have updated repository with your files

Could this connection be true?

$zones = new \Cloudflare\API\Endpoints\Zones($adapter);
	$analytics = $zones->getAnalyticsDashboard("bbea500d1b4ca31fd42d9af01950fd6");
	foreach ($analytics as $goster) {
		echo $goster['bandwidth'];
               //echo $goster['uncached'];
	}

@TylerVigario
Copy link
Contributor

You probably don't want a foreach unless you are looping through the "timeseries"

If you want to get bandwidth total should be something like this

$zones = new \Cloudflare\API\Endpoints\Zones($adapter);
$analytics = $zones->getAnalyticsDashboard("bbea500d1b4ca31fd42d9af01950fd6");

echo $analytics->totals->bandwidth->all;

@emresaracoglu
Copy link
Author

Tyler, do you know?
You are great man! 😃 Thank you again

@MeekLogic

@IcyApril
Copy link
Contributor

Released in 1.0.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants