A call to Cloudflare DNS API

My Unify USG still can’t handle Cloudflare Dynamic DNS, so I have to do it the hard way. Create a script to update the DNS records for me the same way I did for Google DNS in this post: https://tokmakov.me/2019/06/09/dynamic-dns-from-behind-a-router/

Luckily, the API is available, and it looks like this:

curl -X PUT "https://api.cloudflare.com/client/v4/zones/<my zone ID>/dns_records/<my dns record ID>" -H "Authorization: Bearer <your API access token>" -H "Content-Type: application/json" --data '{"name": "example.com", "type": "A", "ttl": 1, "content":"127.0.0.1", "proxied":false}'

You can find your zone ID on your cloudfare page for your site. As for the DNS record ID, you can get them by making another call (https://developers.cloudflare.com/api/operations/dns-records-for-a-zone-list-dns-records):

curl --request GET --url https://api.cloudflare.com/client/v4/zones/<your zone ID>/dns_records --header 'Content-Type: application/json' -H "Authorization: Bearer <your API access token>"

And you can get your access token as described here: https://developers.cloudflare.com/fundamentals/api/get-started/create-token/.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.