Here is a bash script I use to update DDNS with CloudFlare, I could use ddclient, but I like this it works for me

apt -y install dnsutils jq curl

#!/usr/bin/env bash

# A bash script to update a Cloudflare DNS A record with the external IP of the source machine
# Used to provide DDNS service for my home
# Needs the DNS record pre-creating on Cloudflare

## Based on with updates to use
## per-zone configurable access tokens available in the API sections of your Cloudflare profile

# Needs dns-utils jq curl
# install with apt install dnsutils jq curl

# Proxy - uncomment and provide details if using a proxy
#export https_proxy=http://<proxyuser>:<proxypassword>@<proxyip>:<proxyport>

# Cloudflare zone is the zone which holds the record

## Cloudflare authentication details
## keep these private

# Get the current external IP address
ip=$(curl -s -X GET

#echo "Current IP is $ip"

if host $dnsrecord | grep "has address" | grep "$ip"; then
#  echo "$dnsrecord is currently set to $ip; no changes needed"

# if here, the dns record needs updating

# get the dns record id
dnsrecordid=$(curl -s -X GET "$zoneid/dns_records?type=A&name=$dnsrecord" \
  -H "Authorization: Bearer $cloudflare_auth_key" \
  -H "Content-Type: application/json" | jq -r  '{"result"}[] | .[0] | .id')

# update the record
curl -s -X PUT "$zoneid/dns_records/$dnsrecordid" \
  -H "Authorization: Bearer $cloudflare_auth_key" \
  -H "Content-Type: application/json" \
  --data "{\"type\":\"A\",\"name\":\"$dnsrecord\",\"content\":\"$ip\",\"ttl\":1,\"proxied\":false}" | jq