Search help: |
Type what you're looking for. We will try to find it for you! |
|---|
This page document's CloudFlare's Client Interface API. The Client Interface API is used to check or modify the settings of a CloudFlare account.
This API will allow you to:
To interface with the CloudFlare Client Interface API you will need:
You may interface with the API via HTTPS POST or GET requests to www.cloudflare.com/api_json.html. Unencrypted HTTP requests are not supported. (This means you *must* use HTTPS.) Responses are returned in a JSON format.
Ask for a JSONP callback by appending a &callback=mycallback parameter.
Note that all calls are rate limited to 300 per hour, unless otherwise specified. Check the number of calls remaining by adding the parameter &calls_left to any request.
$url = "https://www.cloudflare.com/api_json.html";
$data = array( "a" => "stats", "z" => "example.com", "u" => "[email protected]", "tkn" => "799df833d7a42adf3b8e2fd113c7260b955b8e95ac42c", );
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_FORBID_REUSE, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data ); curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$http_result = curl_exec($ch); $error = curl_error($ch);
$http_code = curl_getinfo($ch ,CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code != 200) {
print "Error: $error\n";
} else {
print_r(json_decode($http_result));
}
Retrieve the current stats and settings for a particular website. This function can be used to get currently settings of values such as the security level.
[a] = stats [tkn] = Your API Key [email] = [email protected] [z] = example.com [interval] = 20 --- see below.
{"response":{"result":{"timeZero":1287797054000,"count":1,"has_more":false,"objs":[{"cachedServerTime":1290561854000,"cachedExpryTime":1290605054000,"trafficBreakdown":{"pageviews":{"regular":195,"threat":1,"crawler":20},"uniques":{"regular":17,"threat":1,"crawler":10}},"bandwidthServed":{"cloudflare":1497.6806640625,"user":1037.56640625},"requestsServed":{"cloudflare":715,"user":400},"pageLoadTime":{"without":0.47,"cloudflare":0.31},"totalUserTimeSaved":null,"currentServerTime":1290561855000,"interval":20,"userSecuritySetting":"High",dev_mode: 0}]}},"result":"success","msg":null}
pageviews -- Number of Page Views in the last 30 days, broken up by type. uniques -- Number of unique IP Addresses, broken up by type. bandwidthServed -- Number of Bytes send from your server to CloudFlare (user), and from CloudFlare to others on your behalf (cloudflare). requestsServed -- Number of raw requests handled by CloudFlare (cloudflare), and requests which were forwarded to your server (user). pageLoadTime -- Average time taken to load a page view with CloudFlare (cloudflare), and without (without). userSecuritySetting -- Current user security setting. dev_mode -- Is the zone currently in dev_mode? 0 if never. Otherwise, timestamp of when dev_move last ended (if in the past) or will end (if in the future).
The interval parameter defines what period you want to look at. Default is 30 days, but 1 day delayed. Pro only intervals are 100, 110, and 120.
10 = 1 year (between 366 and 1 days ago) 20 = 30 day (between 31 and 1 days ago) 30 = 7 day (between 8 and 1 days ago) 40 = 24 hours ago (between 2 and 1 days ago)
<pro only>
100 = 24 hours ago (between 24 and 0 hours ago) 110 = 12 hours ago (between 12 and 0 hour ago) 120 = 6 hours ago (between 6 and 0 hours ago)
This function sets the Basic Security Level to HELP I'M UNDER ATTACK / HIGH / MEDIUM / LOW / ESSENTIALLY OFF.
[a] = sec_lvl [tkn] = Your API Key [email] = [email protected] [z] = example.com [v] = help|high|med|low|eoff
{"result":"success","msg":null}
v must be one of low|med|high|help|eoff
This function sets the Caching Level to Aggressive or Basic.
[a] = cache_lvl [tkn] = Your API Key [email] = [email protected] [z] = example.com [v] = agg|basic
{"result":"success","msg":null}
v must be one of agg|basic
This function allows you to toggle Development Mode on or off for a particular domain. When Development Mode is on the cache is bypassed. Development mode remains on for 3 hours or until when it is toggled back off.
[a] = devmode [tkn] = Your API Key [email] = [email protected] [z] = example.com [v] =1
"v" may be set to 1 (on) or 0 (off).
{"response":{"expires_on":1290572007},"result":"success","msg":null}
Development mode will expire on "expires_on" (3 hours from when it is toggled on). Development mode can be toggled off immediately by setting "v" to 0.
This function will purge CloudFlare of any cached files. It may take up to 48 hours for the cache to rebuild and optimum performance to be achieved so this function should be used sparingly.
[a] = fpurge_ts [tkn] = Your API Key [email] = [email protected] [z] = example.com [v] = 1
{"response":{"fpurge_ts":1290561459},"result":"success","msg":null,"attributes":{"cooldown":20}}
fpurge_ts -- time at which cache was purged cooldown -- number of seconds before the next time this call is allowed again.
Check whether one or more websites/domains are active under an account and return the zone ids (zids) for these.
[a] = zone_check [tkn] = Your API Key [email] = [email protected] [zones] = example.com,anotherexample.com,yetanotherexample.com
{"response":{"zones":{"linuxdating.com":1099,"supertriceratops.com":2018,"ld.com":0,"unspam.com":0}},"result":"success","msg":null}
result -- Map of passed in zones. If a zone if hosted on CloudFlare AND the email + tkn combination is correct for the given zone, the value for the zone will be its zone id (use this for other API calls). Otherwise 0.
Returns a list of IP addresses which hit your site classified by type.
[a] = zone_ips [tkn] = Your API Key [email] = [email protected] [zid] = ID of the zone you would like to check. [hours] = Number of hours to go back. Default is 24, max is 48. [class] = Restrict the result set to a given class. Currently r|s|t, for regular, crawler, threat resp. [geo] = Optional token. Add to add longitude and latitude information to the response. 0,0 means no data.
{"response":{"ips":[{ip: "50.17.204.51", classification: "regular", hits: 6}]},"result":"success","msg":null}
Tells CloudFlare to take a new image of your site.
[a] = zone_grab [tkn] = Your API Key [email] = [email protected] [zid] = ID of the zone you would like to check.
{"response":{"set":[{time: 1303943984}]},"result":"success","msg":null}
Note that this call is rate limited to once per zone per day. Also the new image may take up to 1 hour to appear.
Used to alert CloudFlare of spam which your site received.
Make a GET request to the following URL: https://www.cloudflare.com/ajax/external-event.html. Use the parameters:
[u] = [email protected] [tkn] = Your API Key [evnt_t] = CF_USER_SPAM [evnt_v] = a json encoded array of the form: array("a" => author of spam, "am" => author email, "ip" => offending IP, "content" => up to 100 characters of the spam);
Make sure to also url_encode the jsonafied array.
Note that this call is rate limited to 150 calls per hour.
You can add an IP address to your white or black lists.
Make a GET request to the following url:
https://www.cloudflare.com/api.html?a=wl&key=116.74.99.115&u=[email protected]&tkn=cf-auth-token.
Parameters include
a -- The action you wish to make. Possible values are "wl" for white-listing and "ban" for black listing. key -- The address you wish to set a rule for. u -- The email you use to log in to cloudflare.com. tkn -- Your CloudFlare authentication token. Get one by going to the my-account section of cloudflare.com.
On success returns string OK
On failure returns:
E_UNAUTH -- Authorization could not be completed. E_INVLDIP -- Malformed IPv4 address passed in. E_INVLDINPUT -- Some other input was not valid. E_MAXAPI -- You have exceeded your allowed number of API calls.
Creates a new DNS record for your site. This can be either a CNAME or A record.
[a] =rec_set [tkn] = Your API Key [zone] = zone [email] = [email protected] [type] = A|CNAME [content] = The value of the cname or IP address (the destination). [name] = The name of the record you wish to create. [service_mode] = 0 or 1. 0 means CloudFlare is off (grey cloud) for the new zone, while 1 means a happy orange cloud.
{"response":{"result":"success","msg":null}}
Deletes an existing DNS record.
[a] =rec_del [tkn] = Your API Key [zone] = zone [email] = [email protected] [name] = The name of the record you wish to remove.
Note: all records of the given name will be deleted. For this reason, you must pass in the full DNS name of the record you wish to remove. For example, sub.foo.com, as opposed to just sub.
{"response":{"result":"success","msg":null}}
Purges the preloader's cache.
[a] =pre_purge [tkn] = Your API Key [zone_name] = IP Address [email] = Email
Note, can take up to an hour for this to take effect.
{"response":{"result":"success","msg":null}}
Update a DNS record for your site. This needs to be an A record.
[a] = DIUP [tkn] = Your API Key [u] = [email protected] [ip] = The value of the IP address (the destination). [hosts] = The name of the record you wish to adjust.
{"response":{"result":"success","msg":null}}
Find the current threat score for a given IP. Note that scores are logarithmically increasing, like the Richter scale.
[a] = ip_lkup [tkn] = Your API Key [u] = [email protected] [ip] = IP to check
{response: {1.0.171.33: "BAD:11"}, result: "success", msg: null}
Where BAD marks a threat, SE marks a search engine.
Toggles ipv6 support for a site.
[a] = ipv46 [tkn] = Your API Key [u] = [email protected] [z] = mysite.com [v] = [0|1] --- 0 disables, 1 enables support.
{"response":{"result":"success","msg":null}}
For all calls, errors result in the following response: {"result":"error","msg":"Detailed error message","err_code":"Code"}
For example: {"result":"error","msg":"Invalid zone name","err_code":"E_UNAUTH"}