# Cloudflare DynDNS Update

**URL:** <https://discourse.nodered.org/t/cloudflare-dyndns-update/84257>\
**Category:** General\
**Created:** [3 January 2024 14:10 UTC](https://discourse.nodered.org/t/cloudflare-dyndns-update/84257 "2024-01-03T14:10:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [3 January 2024 14:10 UTC](https://discourse.nodered.org/t/cloudflare-dyndns-update/84257/1 "2024-01-03T14:10:11Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [3 January 2024 19:55 UTC](https://discourse.nodered.org/t/cloudflare-dyndns-update/84257/2 "2024-01-03T19:55:15Z")

</div>

This is how I do it.

```auto
   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](http://mySite.co.uk)** with your own credentials.

Here is the complete flow...

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [3 January 2024 20:26 UTC](https://discourse.nodered.org/t/cloudflare-dyndns-update/84257/3 "2024-01-03T20:26:58Z")

</div>

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

Update DynDNS:  
Inject your IP:

```auto
[
    {
        "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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/a/4a10ea5f28b69d16d4a52553ebafec6fd0d48e55.png)

_proxied true or false_  
_for IPv6: AAAA_

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

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

```auto
[
    {
        "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  
...

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [17 January 2024 20:27 UTC](https://discourse.nodered.org/t/cloudflare-dyndns-update/84257/4 "2024-01-17T20:27:35Z")

</div>

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