Cloudflare DynDNS Update

Hi, do you know how to create a http request for updating my Cloudflare DNS?
the Cloudflare Api docu says:

curl --request PUT \
  --url https://api.cloudflare.com/client/v4/zones/zone_identifier/dns_records/identifier \
  --header 'Content-Type: application/json' \
  --header 'X-Auth-Email: ' \
  --data '{
  "content": "198.51.100.4",
  "name": "example.com",
  "proxied": false,
  "type": "A",
  "comment": "Domain verification record",
  "tags": [
    "owner:dns-team"
  ],
  "ttl": 3600
}'

I have to update 3 zones, A & AAAA.

greetings

This is how I do it.

   curl -X PUT "https://api.cloudflare.com/client/v4/zones/zoneID/dns_records/ID" \
     -H "X-Auth-Email: emailAddress" \
     -H "X-Auth-Key: GlobalAPIkey" \
     -H "Content-Type: application/json" \
     --data '{"type":"A","name":"mySite.co.uk","content":"{{payload}}","ttl":1,"proxied":false}'

Just replace the zoneID, ID, emailAddress, GlobalAPIkey and mySite.co.uk with your own credentials.

Here is the complete flow...

[{"id":"fe8bc493e5130c77","type":"inject","z":"b3b413d1.05b1b","name":"","props":[{"p":"url","v":"https://api.ipify.org/","vt":"str"}],"repeat":"900","crontab":"","once":true,"onceDelay":0.1,"topic":"","x":225,"y":1695,"wires":[["99d9a0197cbc1015"]]},{"id":"492bc2be14a8aaf9","type":"template","z":"b3b413d1.05b1b","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"   curl -X PUT \"https://api.cloudflare.com/client/v4/zones/zoneID/dns_records/ID\" \\\n     -H \"X-Auth-Email: emailAddress\" \\\n     -H \"X-Auth-Key: GlobalAPIkey\" \\\n     -H \"Content-Type: application/json\" \\\n     --data '{\"type\":\"A\",\"name\":\"mySite.co.uk\",\"content\":\"{{payload}}\",\"ttl\":1,\"proxied\":false}'","output":"str","x":515,"y":1695,"wires":[["b49cf8ef9ab9b838"]]},{"id":"b49cf8ef9ab9b838","type":"exec","z":"b3b413d1.05b1b","command":"","addpay":"payload","append":"","useSpawn":"false","timer":"60","winHide":false,"oldrc":false,"name":"","x":620,"y":1695,"wires":[[],[],[]],"l":false},{"id":"99d9a0197cbc1015","type":"http request","z":"b3b413d1.05b1b","name":"Obtain IP","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":365,"y":1695,"wires":[["492bc2be14a8aaf9"]]}]
1 Like

thanks, I tried a few hours on my own, with success:

Update DynDNS:
Inject your IP:

[
    {
        "id": "b91e83e0f7871983",
        "type": "function",
        "z": "74b0442752a49876",
        "name": "Cloudflare",
        "func": "let IP = msg.payload;\nconst headers = {};\nheaders[\"Content-Type\"] = \"application/json\";\nheaders[\"X-Auth-Key\"] = \"Global API Key\";\nheaders[\"X-Auth-Email\"] = \"you@email.com\";\nmsg.method = \"PUT\";\nmsg.headers = headers;\nmsg.url = \"https://api.cloudflare.com/client/v4/zones/<your Zone ID>/dns_records/<your DNS Record ID>\";\nmsg.payload = {\"content\":IP,\"name\":\"mydomain.com\",\"proxied\":false,\"type\":\"A\",\"ttl\":60};\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 948,
        "y": 802,
        "wires": [
            [
                "26c84f3f549233bf"
            ]
        ]
    },
    {
        "id": "26c84f3f549233bf",
        "type": "http request",
        "z": "74b0442752a49876",
        "name": "Cloudflare",
        "method": "use",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 1158,
        "y": 802,
        "wires": [
            []
        ]
    }
]

grafik

proxied true or false
for IPv6: AAAA

(I´ve build these nodes 3x for A, AAAA at mydomain.com + AAAA at sub.mydomain.com)

to get your DNS Record IDs, you have to query first all your zones:

[
    {
        "id": "d5b74fd1cfbc7fc0",
        "type": "http request",
        "z": "74b0442752a49876",
        "name": "Cloudflare",
        "method": "use",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 430,
        "y": 900,
        "wires": [
            [
                "88dea0d47cdc0a1c"
            ]
        ]
    },
    {
        "id": "443f3591bacd1345",
        "type": "inject",
        "z": "74b0442752a49876",
        "name": "Request",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 420,
        "y": 820,
        "wires": [
            [
                "d807163b602bfeb0"
            ]
        ]
    },
    {
        "id": "d807163b602bfeb0",
        "type": "function",
        "z": "74b0442752a49876",
        "name": "Cloudflare request",
        "func": "const headers = {};\nheaders[\"Content-Type\"] = \"application/json\";\nheaders[\"X-Auth-Key\"] = \"your Global Api Key\";\nheaders[\"X-Auth-Email\"] = \"you@email.com\";\nmsg.method = \"GET\";\nmsg.headers = headers;\nmsg.url = \"https://api.cloudflare.com/client/v4/zones/<your Zone ID>/dns_records/\";\nmsg.payload = {};\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 450,
        "y": 860,
        "wires": [
            [
                "d5b74fd1cfbc7fc0"
            ]
        ]
    },
    {
        "id": "88dea0d47cdc0a1c",
        "type": "debug",
        "z": "74b0442752a49876",
        "name": "Cloudflare",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 430,
        "y": 940,
        "wires": []
    }
]

you´ll get an array with all your zones (and IDs):
payload.result[0].id
payload.result[1].id
...

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.