Get all Zone Setting - this could be smarter

As part of my CMS I output all of the site’s Cloudflare zone settings in a single page. I grouped them by type so it’s easily understood by lay folk: Performance, Site Security, and User Security.

This was easy on the previous API because it returned a named structure. After deSerializing the json, I could output result.objs[0].dev_mode.

In the new API I have to loop through the array until I find the matching name… if result[i] = 'development_mode'. That’s goofy. I guess I can make 43 API calls instead :roll_eyes:

Please please please consider adding an option so that we can get a named structure returned instead of an array.


Response would be like…

    "success": true,
    "errors": [],
    "messages": [],
    "result": {
        "always_online": {
            "id": "always_online",
            "value": "on",
            "editable": true,
            "modified_on": "2014-01-01T05:20:00.12345Z"
        "always_use_https": {
            "id": "always_use_https",
            "value": "off",
            "editable": true,
            "modified_on": "undefined"
    "result_info": {
        "page": 1,
        "per_page": 20,
        "count": 1,
        "total_count": 2000

We could then once again call the data simply: result.always_online.value.

PS - the </> function here doesn’t work on json, unless wrapped in a PRE.

Well, here’s a workaround. Basically get the array and turn it into the structure I was requesting above. The code is in CFML but the logic can be applied to any other language. Hopefully this will help someone else with the same need.

  1. fetch the settings
	method="GET" result="cFlare2" charset="utf-8">
  1. deSearialize the filecontent as json and grab the ‘result’
<cfset results = deserializejson(cFlare2.filecontent).result>

… giving us this array:

  1. loop through that array to populate a structure
<cfloop from="1" to="#arrayLen(results)#" index="r">
     <cfset myNewStuct["#results[r].id#"] = results[r]>
<cfset results = myNewStuct>

… giving us a new structure to query against:

Now we can very neatly display settings

<cfif results.advanced_ddos.value eq 'on'>
	<span class="label label-success">Advanced</span>
	<span class="label label-warning">Basic</span>