Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. @hklcf hklcf created this gist Nov 14, 2016.
    47 changes: 47 additions & 0 deletions Cloudflare API (List DNS record).html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <meta name="author" content="HKLCF">
    <title>Cloudflare API (List DNS record)</title>
    </head>
    <body>
    <div id="result"></div>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script>
    cors_proxy = "https://cors-anywhere.herokuapp.com/"; // CORS bypass
    domain_id = ""; // your domain id
    email = ""; // your cloudflare login email
    auth_key = ""; // your auth key <https://www.cloudflare.com/a/account/my-account>
    $.ajax({
    url: cors_proxy + "https://api.cloudflare.com/client/v4/zones/" + domain_id + "/dns_records",
    type: "GET",
    beforeSend: function(xhr) {
    xhr.setRequestHeader("X-Auth-Email", email);
    xhr.setRequestHeader("X-Auth-Key", auth_key);
    },
    data: {
    },
    dataType: "json",
    success: function(data) {
    if(data.result[0]) {
    $(data.result).each(function(list) {
    $("#result").append("ID: ");
    $("#result").append(this.id); // get dns record id
    $("#result").append("<br>");
    $("#result").append("Domain: ");
    $("#result").append(this.name); // get dns record name
    $("#result").append("<br>");
    });
    } else {
    $("#result").append("DNS record not find");
    }
    },
    error: function() {
    $("#result").append("Login Error");
    }
    });
    </script>
    </body>
    </html>